Example #1
0
        private Mesh ImportMesh(geometry geom, mesh mesh, VertexDescriptor vertexFormat)
        {
            var  collada   = new ColladaMesh();
            bool isSkinned = SkinnedMeshes.Contains(geom.id);

            collada.ImportFromCollada(mesh, vertexFormat, isSkinned, Options);

            var m = new Mesh();

            m.VertexFormat = collada.InternalVertexType;
            m.Name         = "Unnamed";

            m.PrimaryVertexData          = new VertexData();
            m.PrimaryVertexData.Vertices = collada.ConsolidatedVertices;

            if (!Options.StripMetadata)
            {
                var components = m.VertexFormat.ComponentNames().Select(s => new GrannyString(s)).ToList();
                m.PrimaryVertexData.VertexComponentNames = components;
            }
            else
            {
                m.PrimaryVertexData.VertexComponentNames = null;
            }

            m.PrimaryTopology         = new TriTopology();
            m.PrimaryTopology.Indices = collada.ConsolidatedIndices;
            m.PrimaryTopology.Groups  = new List <TriTopologyGroup>();
            var triGroup = new TriTopologyGroup();

            triGroup.MaterialIndex = 0;
            triGroup.TriFirst      = 0;
            triGroup.TriCount      = collada.TriangleCount;
            m.PrimaryTopology.Groups.Add(triGroup);

            m.MaterialBindings = new List <MaterialBinding>();
            m.MaterialBindings.Add(new MaterialBinding());

            // m.BoneBindings; - TODO

            m.OriginalToConsolidatedVertexIndexMap = collada.OriginalToConsolidatedVertexIndexMap;

            var divModelType = FindDivModelType(mesh);

            if (divModelType != 0)
            {
                m.ModelType            = divModelType;
                m.HasDefiniteModelType = true;
            }

            Utils.Info(String.Format("Imported {0} mesh ({1} tri groups, {2} tris)",
                                     (m.VertexFormat.HasBoneWeights ? "skinned" : "rigid"),
                                     m.PrimaryTopology.Groups.Count,
                                     collada.TriangleCount));

            return(m);
        }
Example #2
0
        public static Mesh ImportFromCollada(mesh mesh, string vertexFormat, bool rebuildNormals = false, bool rebuildTangents = false)
        {
            var collada = new ColladaMesh();

            collada.ImportFromCollada(mesh, vertexFormat, rebuildNormals, rebuildTangents);

            var m = new Mesh();

            m.VertexFormat = VertexFormatRegistry.Resolve(vertexFormat);
            m.Name         = "Unnamed";

            m.PrimaryVertexData = new VertexData();
            var components = new List <GrannyString>();

            components.Add(new GrannyString("Position"));

            var vertexDesc = Vertex.Description(m.VertexFormat);

            if (vertexDesc.BoneWeights)
            {
                components.Add(new GrannyString("BoneWeights"));
                components.Add(new GrannyString("BoneIndices"));
            }

            components.Add(new GrannyString("Normal"));
            components.Add(new GrannyString("Tangent"));
            components.Add(new GrannyString("Binormal"));
            components.Add(new GrannyString("MaxChannel_1"));
            m.PrimaryVertexData.VertexComponentNames = components;
            m.PrimaryVertexData.Vertices             = collada.ConsolidatedVertices;

            m.PrimaryTopology         = new TriTopology();
            m.PrimaryTopology.Indices = collada.ConsolidatedIndices;
            m.PrimaryTopology.Groups  = new List <TriTopologyGroup>();
            var triGroup = new TriTopologyGroup();

            triGroup.MaterialIndex = 0;
            triGroup.TriFirst      = 0;
            triGroup.TriCount      = collada.TriangleCount;
            m.PrimaryTopology.Groups.Add(triGroup);

            m.MaterialBindings = new List <MaterialBinding>();
            m.MaterialBindings.Add(new MaterialBinding());

            // m.BoneBindings; - TODO

            m.OriginalToConsolidatedVertexIndexMap = collada.OriginalToConsolidatedVertexIndexMap;
            Utils.Info(String.Format("Imported {0} mesh ({1} tri groups, {2} tris)", (vertexDesc.BoneWeights ? "skinned" : "rigid"), m.PrimaryTopology.Groups.Count, collada.TriangleCount));

            return(m);
        }
Example #3
0
        private Mesh ImportMesh(geometry geom, mesh mesh, string vertexFormat)
        {
            var  collada   = new ColladaMesh();
            bool isSkinned = SkinnedMeshes.Contains(geom.id);

            collada.ImportFromCollada(mesh, vertexFormat, isSkinned, Options);

            var m = new Mesh();

            m.VertexFormat = collada.InternalVertexType;
            m.Name         = "Unnamed";

            m.PrimaryVertexData = new VertexData();
            var components = new List <GrannyString>();

            components.Add(new GrannyString("Position"));

            var vertexDesc = Vertex.Description(m.VertexFormat);

            if (vertexDesc.BoneWeights)
            {
                components.Add(new GrannyString("BoneWeights"));
                components.Add(new GrannyString("BoneIndices"));
            }

            if (vertexDesc.Normal)
            {
                components.Add(new GrannyString("Normal"));
            }

            if (vertexDesc.Tangent)
            {
                components.Add(new GrannyString("Tangent"));
            }

            if (vertexDesc.Binormal)
            {
                components.Add(new GrannyString("Binormal"));
            }

            for (int i = 0; i < vertexDesc.DiffuseColors; i++)
            {
                components.Add(new GrannyString("DiffuseColor" + i.ToString()));
            }

            for (int i = 0; i < vertexDesc.TextureCoordinates; i++)
            {
                components.Add(new GrannyString("TextureCoordinate" + i.ToString()));
            }

            m.PrimaryVertexData.VertexComponentNames = components;
            m.PrimaryVertexData.Vertices             = collada.ConsolidatedVertices;

            m.PrimaryTopology         = new TriTopology();
            m.PrimaryTopology.Indices = collada.ConsolidatedIndices;
            m.PrimaryTopology.Groups  = new List <TriTopologyGroup>();
            var triGroup = new TriTopologyGroup();

            triGroup.MaterialIndex = 0;
            triGroup.TriFirst      = 0;
            triGroup.TriCount      = collada.TriangleCount;
            m.PrimaryTopology.Groups.Add(triGroup);

            m.MaterialBindings = new List <MaterialBinding>();
            m.MaterialBindings.Add(new MaterialBinding());

            // m.BoneBindings; - TODO

            m.OriginalToConsolidatedVertexIndexMap = collada.OriginalToConsolidatedVertexIndexMap;
            Utils.Info(String.Format("Imported {0} mesh ({1} tri groups, {2} tris)", (vertexDesc.BoneWeights ? "skinned" : "rigid"), m.PrimaryTopology.Groups.Count, collada.TriangleCount));

            return(m);
        }