当前位置: 首页>>代码示例>>C#>>正文


C# Geometry.SetData方法代码示例

本文整理汇总了C#中Geometry.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# Geometry.SetData方法的具体用法?C# Geometry.SetData怎么用?C# Geometry.SetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Geometry的用法示例。


在下文中一共展示了Geometry.SetData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateMesh

        private void CreateMesh(ModelFile model)
        {
            var id      = "Mesh-"+model.Descriptions[0];
            var name    = model.Descriptions[1];
            var mesh    = new Mesh(id, name);
            var geom    = new Geometry("Geom-"+id, name);
            var node    = Bones.FirstOrDefault(i => i.Name == name);
            var pos     = new GeometryChannel("Pos-"+id, name, GeometrySemantic.Position, 0);
            var nrm     = new GeometryChannel("Nrm-"+id, name, GeometrySemantic.Normal,   0);
            var tex     = new GeometryChannel("Tex-"+id, name, GeometrySemantic.TexCoord, 1);
            var indices = new List<int>();
            var mats    = Materials.Values.ToArray();
            var no      = 0;

            foreach(var i in model.Mesh.Primitives)
            {
                var prim    = new TrianglePrimitive();
                prim.Start  = indices.Count;

                indices.AddRange(i.Indices.Select(j => (int)j));

                prim.Count  = indices.Count - prim.Start;
                prim.Material= mats[no++];

                mesh.Primitives.Add(prim);
            }

            pos.SetData(ToSlimDX(model.Mesh.Vertices.Select(i => i.P)).ToList());
            nrm.SetData(ToSlimDX(model.Mesh.Vertices.Select(i => i.N)).ToList());
            tex.SetData(ToSlimDX(model.Mesh.Vertices.Select(i => i.T)).ToList());
            var array   = indices.ToArray();

            pos.SetIndices(array);
            nrm.SetIndices(array);
            tex.SetIndices(array);

            mesh.Channels.Add(pos);
            mesh.Channels.Add(nrm);
            mesh.Channels.Add(tex);

            geom.SetData(mesh);

            Root.Instances.Add(geom);

            // モーフィング
            if(Settings.Morph)
            {
                Morph       = new MorphingDeclaraion() { ID= "Morph-"+id, Name= "Morph"+name, Method= MorphingMethod.Normalized };
                var morphs  = model.Params.OfType<ParamMorph>().ToArray();

                foreach(var i in morphs)
                {
                    var v   = ToSlimDX(model.Mesh.Vertices.Select(j => j.P)).ToArray();

                    foreach(var j in i.Vertices)
                    {
                        v[j.Index].X    +=j.X;
                        v[j.Index].Y    +=j.Y;
                        v[j.Index].Z    +=j.Z;
                    }

                    var mm  = new Mesh()            { ID= "MorphMesh-"   +i.Name, Name= i.Name };
                    var mg  = new Geometry()        { ID= "MorphGeom-"   +i.Name, Name= i.Name };
                    var mc  = new MorphingChannel() { ID= "MorphChannel-"+i.Name, Name= i.Name, Weight= 0.0f, Geometry= mg };
                    var c   = new GeometryChannel() { ID= "MorphPos-"    +i.Name, Name= i.Name, Semantic= GeometrySemantic.Position, Index= 0 };

                    Morph.Channels.Add(mc);
                    Root.Instances.Add(mg);
                    mg.SetData(mm);
                    mm.Channels.Add(c);
                    mm.Primitives.AddRange(mesh.Primitives);
                    c.SetData(v.ToList());
                    c.SetIndices(mesh.Channels[0].GetIndicesAsArray(mesh));
                }

                Root.Instances.Add(Morph);
            }

            // スキン
            if(Settings.Skin)
            {
                Skin        = new SkinDeclaraion() { ID= "Skin-"+id, Name= "Skin"+name, Bind= SlimDX.Matrix.Identity };
                var skinbones= model.Mesh.RefBones.Select(i => Bones.First(j => j.Name == i.Name)).ToList();
                var bonemats= model.Mesh.RefBones.Select(i =>
                    new SlimDX.Matrix() {
                        M11 = i.Matrix[ 0], M12 = i.Matrix[ 1], M13 = i.Matrix[ 2], M14 = i.Matrix[ 3],
                        M21 = i.Matrix[ 4], M22 = i.Matrix[ 5], M23 = i.Matrix[ 6], M24 = i.Matrix[ 7],
                        M31 = i.Matrix[ 8], M32 = i.Matrix[ 9], M33 = i.Matrix[10], M34 = i.Matrix[11],
                        M41 = i.Matrix[12], M42 = i.Matrix[13], M43 = i.Matrix[14], M44 = i.Matrix[15] }).ToList();

                Skin.Skeleton   = new Skeleton() { Node= Scene.Nodes.First() };
                var verts   = new List<SkinVertices>();
                var v       = new List<SkinVertex>();

                foreach(var i in model.Mesh.Skins)
                {
                    v.Clear();

                    if(0 != i.W1)   v.Add(new SkinVertex(i.B1, i.W1));
                    if(0 != i.W2)   v.Add(new SkinVertex(i.B2, i.W2));
//.........这里部分代码省略.........
开发者ID:cm3d2dataviewer,项目名称:CM3D2DataViewer,代码行数:101,代码来源:DaeExporter.cs


注:本文中的Geometry.SetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。