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


C# MeshBuilder.Add方法代码示例

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


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

示例1: Load

        public void Load(string path)
        {
            var reader = new StreamReader(path);

            var positions = new List<Vector3>();
            var norms = new List<Vector3>();
            var texes = new List<Vector2>();
            var objMaterial = new ObjMaterial();
            var builderMap = new Dictionary<Material, MeshBuilder<VertexTNP3>>();

            var material = Material.Default();
            var builder = new MeshBuilder<VertexTNP3>();
            builderMap[material] = builder;

            while (true) {
                var line = reader.ReadLine();
                if (line == null) { break; }

                var parts = line.Split(' ');
                switch (parts[0]) {

                case "v":
                    var v1 = Parse.Float(parts[1]);
                    var v2 = Parse.Float(parts[2]);
                    var v3 = Parse.Float(parts[3]);
                    var vert = new Vector3(v1, v2, v3);
                    positions.Add(vert);
                    break;

                case "vn":
                    var n1 = Parse.Float(parts[1]);
                    var n2 = Parse.Float(parts[2]);
                    var n3 = Parse.Float(parts[3]);
                    var norm = new Vector3(n1, n2, n3);
                    norms.Add(norm);
                    break;

                case "vt":
                    var t1 = Parse.Float(parts[1]);
                    var t2 = Parse.Float(parts[2]);
                    var tex = new Vector2(t1, t2);
                    texes.Add(tex);
                    break;

                case "f":
                    var g1 = parts[1].Split('/');
                    var g2 = parts[2].Split('/');
                    var g3 = parts[3].Split('/');
                    var tri = new Triangle<VertexTNP3>();

                    if (g1[0] != "") tri.A.Position = positions[Parse.Int(g1[0]) - 1];
                    if (g1[1] != "") tri.A.TexCoord = texes[Parse.Int(g1[1]) - 1];
                    if (g1[2] != "") tri.A.Normal = norms[Parse.Int(g1[2]) - 1];
                    if (g2[0] != "") tri.B.Position = positions[Parse.Int(g2[0]) - 1];
                    if (g2[1] != "") tri.B.TexCoord = texes[Parse.Int(g2[1]) - 1];
                    if (g2[2] != "") tri.B.Normal = norms[Parse.Int(g2[2]) - 1];
                    if (g3[0] != "") tri.C.Position = positions[Parse.Int(g3[0]) - 1];
                    if (g3[1] != "") tri.C.TexCoord = texes[Parse.Int(g3[1]) - 1];
                    if (g3[2] != "") tri.C.Normal = norms[Parse.Int(g3[2]) - 1];
                    builder.Add(tri);
                    break;

                case "mtllib":
                    var dirname = System.IO.Path.GetDirectoryName(path);
                    var mtlPath = Path.Combine(dirname, parts[1]);
                    objMaterial.Load(mtlPath);
                    break;

                case "usemtl":
                    material = objMaterial.Lookup(parts[1]);
                    if (!builderMap.TryGetValue(material, out builder)) {
                        builder = new MeshBuilder<VertexTNP3>();
                        builderMap[material] = builder;
                    }
                    break;
                }
            }

            foreach (var pair in builderMap) {
                if (!pair.Value.IsEmpty) {
                    MaterialGroup mg;
                    mg.Material = pair.Key;
                    mg.Mesh = pair.Value.ToMesh().Compile();
                    materialGroups.Add(mg);
                }
            }
        }
开发者ID:det,项目名称:Rimbalzo,代码行数:87,代码来源:ObjMesh.cs

示例2: makeQuads

        void makeQuads(WallCompiled wall, MeshBuilder<VertexTNP3> builder, int a, int b)
        {
            Quad<VertexTNP3> quad;
            var bottom = wall.Thickness * bottomLength;
            var mid = wall.Thickness * midLength;
            var top = wall.Thickness * topLength;

            Vector3 v1, v2, v3, v4, normal;
            Vector2 t1, t2, t3, t4;

            t1 = new Vector2(.5f, wall.TexesBegin1[a]);
            v1 = new Vector3(wall.Verts1[a].X, wall.Verts1[a].Y, bottom);
            t2 = new Vector2(.5f, wall.TexesEnd1[b]);
            v2 = new Vector3(wall.Verts1[b].X, wall.Verts1[b].Y, bottom);
            t3 = new Vector2(1f, wall.TexesBegin1[a]);
            v3 = new Vector3(wall.Verts1[a].X, wall.Verts1[a].Y, mid);
            t4 = new Vector2(1f, wall.TexesEnd1[b]);
            v4 = new Vector3(wall.Verts1[b].X, wall.Verts1[b].Y, mid);

            normal = Vector3.Cross(v3 - v1, v4 - v1);
            normal.Normalize();

            quad.A.Normal = normal;
            quad.A.Position = v2;
            quad.A.TexCoord = t2;
            quad.B.Normal = normal;
            quad.B.Position = v1;
            quad.B.TexCoord = t1;
            quad.C.Normal = normal;
            quad.C.Position = v3;
            quad.C.TexCoord = t3;
            quad.D.Normal = normal;
            quad.D.Position = v4;
            quad.D.TexCoord = t4;
            builder.Add(quad);

            t1 = new Vector2(.5f, wall.TexesBegin4[a]);
            v1 = new Vector3(wall.Verts4[a].X, wall.Verts4[a].Y, bottom);
            t2 = new Vector2(.5f, wall.TexesEnd4[b]);
            v2 = new Vector3(wall.Verts4[b].X, wall.Verts4[b].Y, bottom);
            t3 = new Vector2(1f, wall.TexesBegin4[a]);
            v3 = new Vector3(wall.Verts4[a].X, wall.Verts4[a].Y, mid);
            t4 = new Vector2(1f, wall.TexesEnd4[b]);
            v4 = new Vector3(wall.Verts4[b].X, wall.Verts4[b].Y, mid);

            normal = Vector3.Cross(v1 - v3, v4 - v3);
            normal.Normalize();

            quad.A.Normal = normal;
            quad.A.Position = v1;
            quad.A.TexCoord = t1;
            quad.B.Normal = normal;
            quad.B.Position = v2;
            quad.B.TexCoord = t2;
            quad.C.Normal = normal;
            quad.C.Position = v4;
            quad.C.TexCoord = t4;
            quad.D.Normal = normal;
            quad.D.Position = v3;
            quad.D.TexCoord = t3;
            builder.Add(quad);

            t1 = new Vector2(.5f, wall.TexesBegin2[a]);
            v1 = new Vector3(wall.Verts2[a].X, wall.Verts2[a].Y, top);
            t2 = new Vector2(.5f, wall.TexesEnd2[b]);
            v2 = new Vector3(wall.Verts2[b].X, wall.Verts2[b].Y, top);
            t3 = new Vector2(1f, wall.TexesBegin3[a]);
            v3 = new Vector3(wall.Verts3[a].X, wall.Verts3[a].Y, top);
            t4 = new Vector2(1f, wall.TexesEnd3[b]);
            v4 = new Vector3(wall.Verts3[b].X, wall.Verts3[b].Y, top);

            normal = Vector3.Cross(v3 - v1, v4 - v1);
            normal.Normalize();

            quad.A.Normal = normal;
            quad.A.Position = v2;
            quad.A.TexCoord = t2;
            quad.B.Normal = normal;
            quad.B.Position = v1;
            quad.B.TexCoord = t1;
            quad.C.Normal = normal;
            quad.C.Position = v3;
            quad.C.TexCoord = t3;
            quad.D.Normal = normal;
            quad.D.Position = v4;
            quad.D.TexCoord = t4;
            builder.Add(quad);

            t1 = new Vector2(0f, wall.TexesBegin1[a]);
            v1 = new Vector3(wall.Verts1[a].X, wall.Verts1[a].Y, mid);
            t2 = new Vector2(0f, wall.TexesEnd1[b]);
            v2 = new Vector3(wall.Verts1[b].X, wall.Verts1[b].Y, mid);
            t3 = new Vector2(.5f, wall.TexesBegin2[a]);
            v3 = new Vector3(wall.Verts2[a].X, wall.Verts2[a].Y, top);
            t4 = new Vector2(.5f, wall.TexesEnd2[b]);
            v4 = new Vector3(wall.Verts2[b].X, wall.Verts2[b].Y, top);

            normal = Vector3.Cross(v3 - v1, v4 - v1);
            normal.Normalize();

//.........这里部分代码省略.........
开发者ID:det,项目名称:Rimbalzo,代码行数:101,代码来源:MapMesh.cs


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