Exemplo n.º 1
0
        public static BasicModel CreateGrid(Device device, float width, float depth, int xVerts, int yVerts)
        {
            var model = new BasicModel();

            model.CreateGridInternal(device, width, depth, xVerts, yVerts);
            return(model);
        }
Exemplo n.º 2
0
        public static BasicModel CreateGeosphere(Device device, float radius, SubdivisionCount numSubdivisions)
        {
            var model = new BasicModel();

            model.CreateGeosphereInternal(device, radius, numSubdivisions);
            return(model);
        }
Exemplo n.º 3
0
        public static BasicModel CreateCylinder(Device device, float bottomRadius, float topRadius, float height, int sliceCount, int stackCount)
        {
            var model = new BasicModel();

            model.CreateCylinderInternal(device, bottomRadius, topRadius, height, sliceCount, stackCount);
            return(model);
        }
Exemplo n.º 4
0
        public static BasicModel CreateSphere(Device device, float radius, int slices, int stacks)
        {
            var model = new BasicModel();

            model.CreateSphereInternal(device, radius, slices, stacks);
            return(model);
        }
Exemplo n.º 5
0
        public static BasicModel CreateBox(Device device, float width, float height, float depth)
        {
            var model = new BasicModel();

            model.CreateBoxInternal(device, width, height, depth);
            return(model);
        }
Exemplo n.º 6
0
        public static BasicModel LoadFromTxtFile(Device device, string filename)
        {
            var vertices = new List <VertPosNormTex>();
            var indices  = new List <int>();
            var vcount   = 0;
            var tcount   = 0;

            using (var reader = new StreamReader(filename)) {
                var input = reader.ReadLine();
                if (input != null)
                {
                    // VertexCount: X
                    vcount = Convert.ToInt32(input.Split(new[] { ':' })[1].Trim());
                }

                input = reader.ReadLine();
                if (input != null)
                {
                    //TriangleCount: X
                    tcount = Convert.ToInt32(input.Split(new[] { ':' })[1].Trim());
                }

                // skip ahead to the vertex data
                do
                {
                    input = reader.ReadLine();
                } while (input != null && !input.StartsWith("{"));
                // Get the vertices
                for (int i = 0; i < vcount; i++)
                {
                    input = reader.ReadLine();
                    if (input != null)
                    {
                        var vals = input.Split(new[] { ' ' });
                        vertices.Add(
                            new VertPosNormTex(
                                new Vector3(
                                    Convert.ToSingle(vals[0].Trim(), CultureInfo.InvariantCulture),
                                    Convert.ToSingle(vals[1].Trim(), CultureInfo.InvariantCulture),
                                    Convert.ToSingle(vals[2].Trim(), CultureInfo.InvariantCulture)),
                                new Vector3(
                                    Convert.ToSingle(vals[3].Trim(), CultureInfo.InvariantCulture),
                                    Convert.ToSingle(vals[4].Trim(), CultureInfo.InvariantCulture),
                                    Convert.ToSingle(vals[5].Trim(), CultureInfo.InvariantCulture)),
                                new Vector2()
                                )
                            );
                    }
                }
                // skip ahead to the index data
                do
                {
                    input = reader.ReadLine();
                } while (input != null && !input.StartsWith("{"));
                // Get the indices

                for (var i = 0; i < tcount; i++)
                {
                    input = reader.ReadLine();
                    if (input == null)
                    {
                        break;
                    }
                    var m = input.Trim().Split(new[] { ' ' });
                    indices.Add(Convert.ToInt32(m[0].Trim()));
                    indices.Add(Convert.ToInt32(m[1].Trim()));
                    indices.Add(Convert.ToInt32(m[2].Trim()));
                }
            }
            var ret = new BasicModel();

            var subset = new MeshSubset()
            {
                FaceCount   = indices.Count / 3,
                FaceStart   = 0,
                VertexCount = vertices.Count,
                VertexStart = 0
            };

            ret.Subsets.Add(subset);
            var max = new Vector3(float.MinValue);
            var min = new Vector3(float.MaxValue);

            foreach (var vertex in vertices)
            {
                max = MathF.Maximize(max, vertex.Position);
                min = MathF.Minimize(min, vertex.Position);
            }
            ret.BoundingBox = new BoundingBox(min, max);

            ret.Vertices.AddRange(vertices.Select(v => new VertPosNormTexTan(v.Position, v.Normal, v.TextureCoords, new Vector3(1, 0, 0))).ToList());
            ret.Indices.AddRange(indices.Select(i => i));

            ret.Materials.Add(new Noire.Common.Material {
                Ambient = Color.Gray, Diffuse = Color.White, Specular = new Color(1f, 1f, 1f, 16f)
            });
            ret.DiffuseMapSRV.Add(null);
            ret.NormalMapSRV.Add(null);

            ret.ModelMesh.SetSubsetTable(ret.Subsets);
            ret.ModelMesh.SetVertices(device, ret.Vertices);
            ret.ModelMesh.SetIndices(device, ret.Indices);

            ret._meshCount = 1;

            return(ret);
        }
Exemplo n.º 7
0
        public static BasicModel LoadSdkMesh(Device device, TextureManager11 texMgr, string filename, string texturePath)
        {
            // NOTE: this assumes that the model file only contains a single mesh
            var sdkMesh = new SdkMesh(filename);
            var ret     = new BasicModel();

            var faceStart   = 0;
            var vertexStart = 0;

            foreach (var sdkMeshSubset in sdkMesh.Subsets)
            {
                var subset = new MeshSubset()
                {
                    FaceCount   = (int)(sdkMeshSubset.IndexCount / 3),
                    FaceStart   = faceStart,
                    VertexCount = (int)sdkMeshSubset.VertexCount,
                    VertexStart = vertexStart
                };
                // fixup any subset indices that assume that all vertices and indices are not in the same buffers
                faceStart   = subset.FaceStart + subset.FaceCount;
                vertexStart = subset.VertexStart + subset.VertexCount;
                ret.Subsets.Add(subset);
            }
            ret._meshCount = ret.SubsetCount;

            var max = new Vector3(float.MinValue);
            var min = new Vector3(float.MaxValue);

            foreach (var vb in sdkMesh.VertexBuffers)
            {
                foreach (var vertex in vb.Vertices)
                {
                    max = MathF.Maximize(max, vertex.Pos);
                    min = MathF.Minimize(min, vertex.Pos);
                    ret.Vertices.Add(vertex);
                }
            }
            ret.BoundingBox = new BoundingBox(min, max);

            foreach (var ib in sdkMesh.IndexBuffers)
            {
                ret.Indices.AddRange(ib.Indices.Select(i => i));
            }
            foreach (var sdkMeshMaterial in sdkMesh.Materials)
            {
                var material = new Noire.Common.Material {
                    Ambient  = sdkMeshMaterial.Ambient,
                    Diffuse  = sdkMeshMaterial.Diffuse,
                    Reflect  = Color.Black,
                    Specular = sdkMeshMaterial.Specular
                };
                material.Specular.Alpha = sdkMeshMaterial.Power;
                ret.Materials.Add(material);
                if (!string.IsNullOrEmpty(sdkMeshMaterial.DiffuseTexture))
                {
                    ret.DiffuseMapSRV.Add(texMgr.CreateTexture(Path.Combine(texturePath, sdkMeshMaterial.DiffuseTexture)));
                }
                else
                {
                    ret.DiffuseMapSRV.Add(texMgr[TextureManager11.TexDefault]);
                }
                if (!string.IsNullOrEmpty(sdkMeshMaterial.NormalTexture))
                {
                    ret.NormalMapSRV.Add(texMgr.CreateTexture(Path.Combine(texturePath, sdkMeshMaterial.NormalTexture)));
                }
                else
                {
                    ret.NormalMapSRV.Add(texMgr[TextureManager11.TexDefaultNorm]);
                }
            }
            ret.ModelMesh.SetSubsetTable(ret.Subsets);
            ret.ModelMesh.SetVertices(device, ret.Vertices);
            ret.ModelMesh.SetIndices(device, ret.Indices);

            return(ret);
        }
Exemplo n.º 8
0
 public BasicModelInstance(BasicModel model)
     : base(model)
 {
 }