Exemplo n.º 1
0
        public void AddRegion(Scene scene)
        {
            if (!m_Enabled)
            {
                return;
            }

            m_scene = scene;

            List <string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());

            if (renderers.Count > 0)
            {
                m_primMesher = RenderingLoader.LoadRenderer(renderers[0]);
                m_log.Info("[MAPTILE]: Loaded prim mesher " + m_primMesher.ToString());
            }
            else
            {
                m_log.Info("[MAPTILE]: No prim mesher loaded, prim rendering will be disabled");
            }

            m_scene.RegisterModuleInterface <IMapImageGenerator>(this);
        }
Exemplo n.º 2
0
        public void AddRegion(Scene scene)
        {
            if (!m_Enabled)
                return;

            m_scene = scene;

            List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
            if (renderers.Count > 0)
            {
                m_primMesher = RenderingLoader.LoadRenderer(renderers[0]);
                m_log.Debug("[MAPTILE]: Loaded prim mesher " + m_primMesher.ToString());
            }
            else
            {
                m_log.Debug("[MAPTILE]: No prim mesher loaded, prim rendering will be disabled");
            }

            m_scene.RegisterModuleInterface<IMapImageGenerator>(this);
        }
Exemplo n.º 3
0
        public Bitmap TerrainToBitmap (System.Drawing.Bitmap mapbmp)
        {
            List<string> renderers = RenderingLoader.ListRenderers (Util.ExecutingDirectory ());
            if (renderers.Count > 0)
            {
                m_primMesher = RenderingLoader.LoadRenderer (renderers[0]);
                m_log.Debug ("[MAPTILE]: Loaded prim mesher " + m_primMesher.ToString ());
            }
            else
            {
                m_log.Info ("[MAPTILE]: No prim mesher loaded, prim rendering will be disabled");
            }

            bool drawPrimVolume = true;
            bool textureTerrain = true;

            try
            {
                IConfig startupConfig = m_config.Configs["Startup"];
                drawPrimVolume = startupConfig.GetBoolean ("DrawPrimOnMapTile", drawPrimVolume);
                textureTerrain = startupConfig.GetBoolean ("TextureOnMapTile", textureTerrain);
            }
            catch
            {
                m_log.Warn ("[MAPTILE]: Failed to load StartupConfig");
            }

            m_texturePrims = m_config.Configs["MapModule"].GetBoolean("WarpTexturePrims", false);
            m_colors.Clear ();

            int scaledRemovalFactor = m_scene.RegionInfo.RegionSizeX / (Constants.RegionSize / 2);
            Vector3 camPos = new Vector3 (m_scene.RegionInfo.RegionSizeX / 2 - 0.5f, m_scene.RegionInfo.RegionSizeY / 2 - 0.5f, 221.7025033688163f);
            Viewport viewport = new Viewport (camPos, -Vector3.UnitZ, 1024f, 0.1f, m_scene.RegionInfo.RegionSizeX - scaledRemovalFactor, m_scene.RegionInfo.RegionSizeY - scaledRemovalFactor, m_scene.RegionInfo.RegionSizeX - scaledRemovalFactor, m_scene.RegionInfo.RegionSizeY - scaledRemovalFactor);

            int width = viewport.Width;
            int height = viewport.Height;

            if (m_useAntiAliasing)
            {
                width *= 2;
                height *= 2;
            }

            WarpRenderer renderer = new WarpRenderer ();
            warp_Object terrainObj = null;
            renderer.CreateScene (width, height);
            renderer.Scene.autoCalcNormals = false;

            #region Camera

            warp_Vector pos = ConvertVector (viewport.Position);
            pos.z -= 0.001f; // Works around an issue with the Warp3D camera
            warp_Vector lookat = warp_Vector.add (ConvertVector (viewport.Position), ConvertVector (viewport.LookDirection));

            renderer.Scene.defaultCamera.setPos (pos);
            renderer.Scene.defaultCamera.lookAt (lookat);

            if (viewport.Orthographic)
            {
                renderer.Scene.defaultCamera.isOrthographic = true;
                renderer.Scene.defaultCamera.orthoViewWidth = viewport.OrthoWindowWidth;
                renderer.Scene.defaultCamera.orthoViewHeight = viewport.OrthoWindowHeight;
            }
            else
            {
                viewport.Orthographic = false;
                float fov = 256;
                //fov *= 1.75f; // FIXME: ???
                renderer.Scene.defaultCamera.setFov (fov);
            }

            #endregion Camera

            renderer.Scene.addLight ("Light1", new warp_Light (new warp_Vector (1.0f, 0.5f, 1f), 0xffffff, 0, 320, 40));
            renderer.Scene.addLight ("Light2", new warp_Light (new warp_Vector (-1f, -1f, 1f), 0xffffff, 0, 100, 40));

            try
            {
                CreateWater (renderer);
                terrainObj = CreateTerrain (renderer, textureTerrain);
                if (drawPrimVolume && m_primMesher != null)
                    foreach (ISceneEntity ent in m_scene.Entities.GetEntities ())
                        foreach (ISceneChildEntity part in ent.ChildrenEntities ())
                            CreatePrim (renderer, part);
            }
            catch(Exception ex)
            {
                m_log.Warn ("[Warp3D]: Exception in the map generation, " + ex.ToString ());
            }

            renderer.Render ();
            Bitmap bitmap = renderer.Scene.getImage ();
            bitmap = ImageUtils.ResizeImage (bitmap, Constants.RegionSize, Constants.RegionSize);

            renderer.Scene.removeAllObjects ();
            renderer = null;
            viewport = null;
            m_primMesher = null;
            terrainObj.fastvertex = null;
            terrainObj.fasttriangle = null;
            terrainObj = null;
            m_colors.Clear ();

            //Force GC to try to clean this mess up
            GC.GetTotalMemory (true);

            return bitmap;
        }
Exemplo n.º 4
0
        public Bitmap TerrainToBitmap(System.Drawing.Bitmap mapbmp)
        {
            mapbmp = new Bitmap (m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY);
            List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
            if (renderers.Count > 0)
            {
                m_primMesher = RenderingLoader.LoadRenderer(renderers[0]);
                m_log.Info("[MAPTILE]: Loaded prim mesher " + m_primMesher.ToString());
            }
            else
            {
                m_log.Info("[MAPTILE]: No prim mesher loaded, prim rendering will be disabled");
            }

            bool drawPrimVolume = true;
            bool textureTerrain = true;

            try
            {
                IConfig startupConfig = m_config.Configs["Startup"];
                drawPrimVolume = startupConfig.GetBoolean("DrawPrimOnMapTile", drawPrimVolume);
                textureTerrain = startupConfig.GetBoolean("TextureOnMapTile", textureTerrain);
            }
            catch
            {
                m_log.Warn("[MAPTILE]: Failed to load StartupConfig");
            }

            m_colors.Clear();

            Vector3 camPos = new Vector3 (m_scene.RegionInfo.RegionSizeX / 2, m_scene.RegionInfo.RegionSizeY / 2, 221.7025033688163f);
            Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f, m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY, m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY);

            int width = viewport.Width;
            int height = viewport.Height;

            if (m_useAntiAliasing)
            {
                width *= 2;
                height *= 2;
            }

            WarpRenderer renderer = new WarpRenderer();
            renderer.CreateScene(width, height);
            renderer.Scene.autoCalcNormals = false;

            #region Camera

            warp_Vector pos = ConvertVector(viewport.Position);
            pos.z -= 0.001f; // Works around an issue with the Warp3D camera
            warp_Vector lookat = warp_Vector.add(ConvertVector(viewport.Position), ConvertVector(viewport.LookDirection));

            renderer.Scene.defaultCamera.setPos(pos);
            renderer.Scene.defaultCamera.lookAt(lookat);

            if (viewport.Orthographic)
            {
                renderer.Scene.defaultCamera.isOrthographic = true;
                renderer.Scene.defaultCamera.orthoViewWidth = viewport.OrthoWindowWidth;
                renderer.Scene.defaultCamera.orthoViewHeight = viewport.OrthoWindowHeight;
            }
            else
            {
                float fov = viewport.FieldOfView;
                fov *= 1.75f; // FIXME: ???
                renderer.Scene.defaultCamera.setFov(fov);
            }

            #endregion Camera

            renderer.Scene.addLight("Light1", new warp_Light(new warp_Vector(0.2f, 0.2f, 1f), 0xffffff, 320, 80));
            renderer.Scene.addLight("Light2", new warp_Light(new warp_Vector(-1f, -1f, 1f), 0xffffff, 100, 40));

            CreateWater(renderer);
            CreateTerrain(renderer, textureTerrain);
            if (drawPrimVolume && m_primMesher != null)
                m_scene.ForEachSOG(delegate (SceneObjectGroup group)
                {
                    group.ForEachPart(delegate(SceneObjectPart part) { CreatePrim(renderer, part); });
                });

            renderer.Render();
            Bitmap bitmap = renderer.Scene.getImage();

            renderer.Scene.removeAllObjects();
            renderer = null;
            viewport = null;
            m_primMesher = null;
            m_colors.Clear();

            //Force GC to try to clean this mess up
            GC.GetTotalMemory(true);

            if (m_useAntiAliasing)
                bitmap = ImageUtils.ResizeImage(bitmap, width / 2, height / 2);

            return bitmap;
        }
Exemplo n.º 5
0
        public Bitmap TerrainToBitmap(System.Drawing.Bitmap mapbmp)
        {
            mapbmp = new Bitmap(m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY);
            List <string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());

            if (renderers.Count > 0)
            {
                m_primMesher = RenderingLoader.LoadRenderer(renderers[0]);
                m_log.Info("[MAPTILE]: Loaded prim mesher " + m_primMesher.ToString());
            }
            else
            {
                m_log.Info("[MAPTILE]: No prim mesher loaded, prim rendering will be disabled");
            }

            bool drawPrimVolume = true;
            bool textureTerrain = true;

            try
            {
                IConfig startupConfig = m_config.Configs["Startup"];
                drawPrimVolume = startupConfig.GetBoolean("DrawPrimOnMapTile", drawPrimVolume);
                textureTerrain = startupConfig.GetBoolean("TextureOnMapTile", textureTerrain);
            }
            catch
            {
                m_log.Warn("[MAPTILE]: Failed to load StartupConfig");
            }

            m_colors.Clear();

            Vector3  camPos   = new Vector3(m_scene.RegionInfo.RegionSizeX / 2, m_scene.RegionInfo.RegionSizeY / 2, 221.7025033688163f);
            Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f, m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY, m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY);

            int width  = viewport.Width;
            int height = viewport.Height;

            if (m_useAntiAliasing)
            {
                width  *= 2;
                height *= 2;
            }

            WarpRenderer renderer = new WarpRenderer();

            renderer.CreateScene(width, height);
            renderer.Scene.autoCalcNormals = false;

            #region Camera

            warp_Vector pos = ConvertVector(viewport.Position);
            pos.z -= 0.001f; // Works around an issue with the Warp3D camera
            warp_Vector lookat = warp_Vector.add(ConvertVector(viewport.Position), ConvertVector(viewport.LookDirection));

            renderer.Scene.defaultCamera.setPos(pos);
            renderer.Scene.defaultCamera.lookAt(lookat);

            if (viewport.Orthographic)
            {
                renderer.Scene.defaultCamera.isOrthographic  = true;
                renderer.Scene.defaultCamera.orthoViewWidth  = viewport.OrthoWindowWidth;
                renderer.Scene.defaultCamera.orthoViewHeight = viewport.OrthoWindowHeight;
            }
            else
            {
                float fov = viewport.FieldOfView;
                fov *= 1.75f; // FIXME: ???
                renderer.Scene.defaultCamera.setFov(fov);
            }

            #endregion Camera

            renderer.Scene.addLight("Light1", new warp_Light(new warp_Vector(0.2f, 0.2f, 1f), 0xffffff, 320, 80));
            renderer.Scene.addLight("Light2", new warp_Light(new warp_Vector(-1f, -1f, 1f), 0xffffff, 100, 40));

            CreateWater(renderer);
            CreateTerrain(renderer, textureTerrain);
            if (drawPrimVolume && m_primMesher != null)
            {
                m_scene.ForEachSOG(delegate(SceneObjectGroup group)
                {
                    group.ForEachPart(delegate(SceneObjectPart part) { CreatePrim(renderer, part); });
                });
            }

            renderer.Render();
            Bitmap bitmap = renderer.Scene.getImage();

            renderer.Scene.removeAllObjects();
            renderer     = null;
            viewport     = null;
            m_primMesher = null;
            m_colors.Clear();

            //Force GC to try to clean this mess up
            GC.GetTotalMemory(true);

            if (m_useAntiAliasing)
            {
                bitmap = ImageUtils.ResizeImage(bitmap, width / 2, height / 2);
            }

            return(bitmap);
        }