public void Render(Scene scene)
 {
     _device.VertexFormat = VertexPositionNormal.Format;
     _device.SetRenderState(RenderState.CullMode, Cull.None);
     RenderSceneObjects(scene.Liquids.Where(l=>(l.MaterialProperties & MaterialFlags.DamageOverTime)!= 0), _harmingLiquidMaterial);
     RenderSceneObjects(scene.Liquids.Where(l => (l.MaterialProperties & MaterialFlags.DamageOverTime) == 0), _waterMaterial);
     _device.SetRenderState(RenderState.CullMode, Cull.Clockwise);
     RenderSceneObjects(scene.Terrain, _terrainMaterial);
     RenderSceneObjects(scene.Doodads, _doodadMaterial);
     RenderSceneObjects(scene.Wmos, _wmoMaterial);
 }
示例#2
0
        private static void DumpAsWavefrontObject(Scene scene, Stream stream)
        {
            var allObjects = scene.Terrain
                .Concat(scene.Liquids)
                .Concat(scene.Wmos)
                .Concat(scene.Doodads);

            // Wavefront objects have exactly one vertex array and one triangle array, which indexes into the vertex array 1-based.
            // Since Vertices and especially vertex indices are stored per SceneObject, we have to copy the vertices and offset
            // the triangle indices:
            var vertices = new List<Vector3>();
            var triangles = new List<IndexedTriangle>();
            foreach (var geo in allObjects.Select(so => so.Geometry))
            {
                var offset = 1 + vertices.Count; // 1-based
                vertices.AddRange(geo.Vertices);
                triangles.AddRange(
                    from t in geo.Triangles
                    select new IndexedTriangle
                    {
                        A = t.A + offset,
                        B = t.B + offset,
                        C = t.C + offset
                    });
            }

            // Now just dump them.
            using (var writer = new StreamWriter(stream))
            {
                writer.WriteLine("o some_adt.obj");
                foreach (var v in vertices)
                {
                    var nf = CultureInfo.InvariantCulture.NumberFormat;
                    writer.WriteLine("v {0} {1} {2}", v.X.ToString(nf), v.Y.ToString(nf), v.Z.ToString(nf));
                }

                foreach (var t in triangles)
                {
                    writer.WriteLine("f {0} {1} {2}", t.A, t.B, t.C);
                }
            }
        }