コード例 #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);
        }
コード例 #2
0
ファイル: Mesh.cs プロジェクト: xenogenesi/lslib
        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);
        }
コード例 #3
0
        private Mesh GenerateDummyMesh(MeshBinding meshBinding)
        {
            var vertexData = new VertexData();

            vertexData.VertexComponentNames = meshBinding.Mesh.PrimaryVertexData.VertexComponentNames
                                              .Select(name => new GrannyString(name.String)).ToList();
            vertexData.Vertices = new List <Vertex>();
            var dummyVertex = meshBinding.Mesh.VertexFormat.CreateInstance();

            vertexData.Vertices.Add(dummyVertex);
            Root.VertexDatas.Add(vertexData);

            var topology = new TriTopology();

            topology.Groups = new List <TriTopologyGroup>();
            var group = new TriTopologyGroup();

            group.MaterialIndex = 0;
            group.TriCount      = 0;
            group.TriFirst      = 0;
            topology.Groups.Add(group);

            topology.Indices = new List <int>();
            Root.TriTopologies.Add(topology);

            var mesh = new Mesh();

            mesh.Name              = meshBinding.Mesh.Name;
            mesh.VertexFormat      = meshBinding.Mesh.VertexFormat;
            mesh.PrimaryTopology   = topology;
            mesh.PrimaryVertexData = vertexData;
            if (meshBinding.Mesh.BoneBindings != null)
            {
                mesh.BoneBindings = new List <BoneBinding>();
                ConformMeshBoneBindings(mesh, meshBinding.Mesh);
            }

            return(mesh);
        }
コード例 #4
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);
        }