From 34c7a0e43a55e60466ce5527722cbdc5c946cd34 Mon Sep 17 00:00:00 2001
From: Adam Frisby
Date: Tue, 26 Jun 2007 04:45:24 +0000
Subject: * Terrain filters! - Think photoshop-style filters for terrain. *
Terrain filters may be written in either C# or JavaScript and loaded at
runtime Use: terrain csfilter somefile.cs -- Loads a C# filter terrain
jsfilter somefile.js -- Loads a JavaScript filter Once a terrain filter has
been loaded, you can use the command as normal, eg terrain demofilter
---
.../OpenSim.Terrain.BasicTerrain.csproj | 39 +++++----
.../OpenSim.Terrain.BasicTerrain/TerrainEngine.cs | 31 ++++++-
.../OpenSim.Terrain.BasicTerrain/TerrainFilter.cs | 97 ++++++++++++++++++++++
OpenSim/OpenSim/OpenSimMain.cs | 13 +--
4 files changed, 156 insertions(+), 24 deletions(-)
create mode 100644 OpenSim/OpenSim.Terrain.BasicTerrain/TerrainFilter.cs
(limited to 'OpenSim')
diff --git a/OpenSim/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj b/OpenSim/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj
index 694521b..419880e 100644
--- a/OpenSim/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj
+++ b/OpenSim/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj
@@ -1,4 +1,4 @@
-
+
Local
8.0.50727
@@ -6,7 +6,8 @@
{2270B8FE-0000-0000-0000-000000000000}
Debug
AnyCPU
-
+
+
OpenSim.Terrain.BasicTerrain
@@ -15,9 +16,11 @@
IE50
false
Library
-
+
+
OpenSim.Terrain.BasicTerrain
-
+
+
@@ -28,7 +31,8 @@
TRACE;DEBUG
-
+
+
True
4096
False
@@ -37,7 +41,8 @@
False
False
4
-
+
+
False
@@ -46,7 +51,8 @@
TRACE
-
+
+
False
4096
True
@@ -55,30 +61,32 @@
False
False
4
-
+
+
-
+
..\..\bin\libTerrain-BSD.dll
False
-
+
+
..\..\bin\openjpegnet.dll
False
-
+
System.dll
False
-
+
System.Data.dll
False
-
+
System.Drawing.dll
False
-
+
System.Xml.dll
False
@@ -92,6 +100,7 @@
Code
+
@@ -100,4 +109,4 @@
-
+
\ No newline at end of file
diff --git a/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
index d1d54ad..2bda5ba 100644
--- a/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
+++ b/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
@@ -48,6 +48,11 @@ namespace OpenSim.Terrain
public class TerrainEngine
{
///
+ /// Plugin library for scripts
+ ///
+ public FilterHost customFilters = new FilterHost();
+
+ ///
/// A [normally] 256x256 heightmap
///
public Channel heightmap;
@@ -193,8 +198,10 @@ namespace OpenSim.Terrain
resultText += "terrain erode aerobic \n";
resultText += "terrain erode thermal \n";
resultText += "terrain multiply - multiplies a terrain by \n";
- resultText += "terrain revert - reverts the terrain to the stored original";
- resultText += "terrain bake - saves the current terrain into the revert map";
+ resultText += "terrain revert - reverts the terrain to the stored original\n";
+ resultText += "terrain bake - saves the current terrain into the revert map\n";
+ resultText += "terrain csfilter - loads a new filter from the specified .cs file\n";
+ resultText += "terrain jsfilter - loads a new filter from the specified .js file\n";
return false;
case "revert":
@@ -285,9 +292,25 @@ namespace OpenSim.Terrain
}
break;
+ case "csfilter":
+ customFilters.LoadFilterCSharp(args[1]);
+ break;
+ case "jsfilter":
+ customFilters.LoadFilterJScript(args[1]);
+ break;
+
default:
- resultText = "Unknown terrain command";
- return false;
+ // Run any custom registered filters
+ if (customFilters.filters.ContainsKey(command))
+ {
+ customFilters.filters[command].Filter(heightmap, args);
+ break;
+ }
+ else
+ {
+ resultText = "Unknown terrain command";
+ return false;
+ }
}
return true;
}
diff --git a/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainFilter.cs b/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainFilter.cs
new file mode 100644
index 0000000..6a83c8a
--- /dev/null
+++ b/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainFilter.cs
@@ -0,0 +1,97 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using System.CodeDom.Compiler;
+using System.CodeDom;
+using Microsoft.CSharp;
+using Microsoft.JScript;
+
+using libTerrain;
+
+namespace OpenSim.Terrain
+{
+ public interface ITerrainFilter
+ {
+ void Filter(Channel heightmap, string[] args);
+ string Register();
+ }
+
+ public class TestFilter : ITerrainFilter
+ {
+ public void Filter(Channel heightmap, string[] args)
+ {
+ Console.WriteLine("Hello world");
+ }
+
+ public string Register()
+ {
+ return "demofilter";
+ }
+ }
+
+ public class FilterHost
+ {
+ public Dictionary filters = new Dictionary();
+
+ private void LoadFilter(ICodeCompiler compiler, string filename)
+ {
+ CompilerParameters compilerParams = new CompilerParameters();
+ CompilerResults compilerResults;
+ compilerParams.GenerateExecutable = false;
+ compilerParams.GenerateInMemory = true;
+ compilerParams.IncludeDebugInformation = false;
+ compilerParams.ReferencedAssemblies.Add("libTerrain-BSD.dll");
+ compilerParams.ReferencedAssemblies.Add("OpenSim.Terrain.BasicTerrain.dll");
+ compilerParams.ReferencedAssemblies.Add("System.dll");
+
+ compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
+
+ if (compilerResults.Errors.Count > 0)
+ {
+ Console.WriteLine("Compile errors:");
+ foreach (CompilerError error in compilerResults.Errors)
+ {
+ Console.WriteLine(error.Line.ToString() + ": " + error.ErrorText.ToString());
+ }
+ }
+ else
+ {
+ foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
+ {
+ Type testInterface = pluginType.GetInterface("ITerrainFilter",true);
+
+ if (testInterface != null)
+ {
+ ITerrainFilter filter = (ITerrainFilter)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
+
+ string filterName = filter.Register();
+ Console.WriteLine("Plugin: " + filterName + " loaded.");
+
+ if (!filters.ContainsKey(filterName))
+ {
+ filters.Add(filterName, filter);
+ }
+ else
+ {
+ filters[filterName] = filter;
+ }
+ }
+ }
+ }
+
+ }
+
+ public void LoadFilterCSharp(string filename)
+ {
+ CSharpCodeProvider compiler = new CSharpCodeProvider();
+ LoadFilter(compiler.CreateCompiler(), filename);
+ }
+
+ public void LoadFilterJScript(string filename)
+ {
+ JScriptCodeProvider compiler = new JScriptCodeProvider();
+ LoadFilter(compiler.CreateCompiler(), filename);
+ }
+ }
+}
diff --git a/OpenSim/OpenSim/OpenSimMain.cs b/OpenSim/OpenSim/OpenSimMain.cs
index ef4aa62..a6ad15d 100644
--- a/OpenSim/OpenSim/OpenSimMain.cs
+++ b/OpenSim/OpenSim/OpenSimMain.cs
@@ -434,11 +434,14 @@ namespace OpenSim
break;
case "terrain":
- //string result = "";
- /* if (!((World)m_localWorld).Terrain.RunTerrainCmd(cmdparams, ref result))
- {
- m_log.Error( result);
- }*/
+ string result = "";
+ for (int i = 0; i < m_localWorld.Count; i++)
+ {
+ if (!((Scene)m_localWorld[i]).Terrain.RunTerrainCmd(cmdparams, ref result))
+ {
+ m_log.Error(result);
+ }
+ }
break;
case "shutdown":
--
cgit v1.1