diff options
author | Adam Frisby | 2007-06-26 04:45:24 +0000 |
---|---|---|
committer | Adam Frisby | 2007-06-26 04:45:24 +0000 |
commit | 34c7a0e43a55e60466ce5527722cbdc5c946cd34 (patch) | |
tree | 3713623e7f4cf7fafdd1ca77a6c2cc74e8149c48 /OpenSim | |
parent | * Committing terrain filter demo (diff) | |
download | opensim-SC-34c7a0e43a55e60466ce5527722cbdc5c946cd34.zip opensim-SC-34c7a0e43a55e60466ce5527722cbdc5c946cd34.tar.gz opensim-SC-34c7a0e43a55e60466ce5527722cbdc5c946cd34.tar.bz2 opensim-SC-34c7a0e43a55e60466ce5527722cbdc5c946cd34.tar.xz |
* 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
Diffstat (limited to '')
4 files changed, 156 insertions, 24 deletions
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 @@ | |||
1 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | 1 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
2 | <PropertyGroup> | 2 | <PropertyGroup> |
3 | <ProjectType>Local</ProjectType> | 3 | <ProjectType>Local</ProjectType> |
4 | <ProductVersion>8.0.50727</ProductVersion> | 4 | <ProductVersion>8.0.50727</ProductVersion> |
@@ -6,7 +6,8 @@ | |||
6 | <ProjectGuid>{2270B8FE-0000-0000-0000-000000000000}</ProjectGuid> | 6 | <ProjectGuid>{2270B8FE-0000-0000-0000-000000000000}</ProjectGuid> |
7 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | 7 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
8 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | 8 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
9 | <ApplicationIcon></ApplicationIcon> | 9 | <ApplicationIcon> |
10 | </ApplicationIcon> | ||
10 | <AssemblyKeyContainerName> | 11 | <AssemblyKeyContainerName> |
11 | </AssemblyKeyContainerName> | 12 | </AssemblyKeyContainerName> |
12 | <AssemblyName>OpenSim.Terrain.BasicTerrain</AssemblyName> | 13 | <AssemblyName>OpenSim.Terrain.BasicTerrain</AssemblyName> |
@@ -15,9 +16,11 @@ | |||
15 | <DefaultTargetSchema>IE50</DefaultTargetSchema> | 16 | <DefaultTargetSchema>IE50</DefaultTargetSchema> |
16 | <DelaySign>false</DelaySign> | 17 | <DelaySign>false</DelaySign> |
17 | <OutputType>Library</OutputType> | 18 | <OutputType>Library</OutputType> |
18 | <AppDesignerFolder></AppDesignerFolder> | 19 | <AppDesignerFolder> |
20 | </AppDesignerFolder> | ||
19 | <RootNamespace>OpenSim.Terrain.BasicTerrain</RootNamespace> | 21 | <RootNamespace>OpenSim.Terrain.BasicTerrain</RootNamespace> |
20 | <StartupObject></StartupObject> | 22 | <StartupObject> |
23 | </StartupObject> | ||
21 | <FileUpgradeFlags> | 24 | <FileUpgradeFlags> |
22 | </FileUpgradeFlags> | 25 | </FileUpgradeFlags> |
23 | </PropertyGroup> | 26 | </PropertyGroup> |
@@ -28,7 +31,8 @@ | |||
28 | <ConfigurationOverrideFile> | 31 | <ConfigurationOverrideFile> |
29 | </ConfigurationOverrideFile> | 32 | </ConfigurationOverrideFile> |
30 | <DefineConstants>TRACE;DEBUG</DefineConstants> | 33 | <DefineConstants>TRACE;DEBUG</DefineConstants> |
31 | <DocumentationFile></DocumentationFile> | 34 | <DocumentationFile> |
35 | </DocumentationFile> | ||
32 | <DebugSymbols>True</DebugSymbols> | 36 | <DebugSymbols>True</DebugSymbols> |
33 | <FileAlignment>4096</FileAlignment> | 37 | <FileAlignment>4096</FileAlignment> |
34 | <Optimize>False</Optimize> | 38 | <Optimize>False</Optimize> |
@@ -37,7 +41,8 @@ | |||
37 | <RemoveIntegerChecks>False</RemoveIntegerChecks> | 41 | <RemoveIntegerChecks>False</RemoveIntegerChecks> |
38 | <TreatWarningsAsErrors>False</TreatWarningsAsErrors> | 42 | <TreatWarningsAsErrors>False</TreatWarningsAsErrors> |
39 | <WarningLevel>4</WarningLevel> | 43 | <WarningLevel>4</WarningLevel> |
40 | <NoWarn></NoWarn> | 44 | <NoWarn> |
45 | </NoWarn> | ||
41 | </PropertyGroup> | 46 | </PropertyGroup> |
42 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | 47 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
43 | <AllowUnsafeBlocks>False</AllowUnsafeBlocks> | 48 | <AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
@@ -46,7 +51,8 @@ | |||
46 | <ConfigurationOverrideFile> | 51 | <ConfigurationOverrideFile> |
47 | </ConfigurationOverrideFile> | 52 | </ConfigurationOverrideFile> |
48 | <DefineConstants>TRACE</DefineConstants> | 53 | <DefineConstants>TRACE</DefineConstants> |
49 | <DocumentationFile></DocumentationFile> | 54 | <DocumentationFile> |
55 | </DocumentationFile> | ||
50 | <DebugSymbols>False</DebugSymbols> | 56 | <DebugSymbols>False</DebugSymbols> |
51 | <FileAlignment>4096</FileAlignment> | 57 | <FileAlignment>4096</FileAlignment> |
52 | <Optimize>True</Optimize> | 58 | <Optimize>True</Optimize> |
@@ -55,30 +61,32 @@ | |||
55 | <RemoveIntegerChecks>False</RemoveIntegerChecks> | 61 | <RemoveIntegerChecks>False</RemoveIntegerChecks> |
56 | <TreatWarningsAsErrors>False</TreatWarningsAsErrors> | 62 | <TreatWarningsAsErrors>False</TreatWarningsAsErrors> |
57 | <WarningLevel>4</WarningLevel> | 63 | <WarningLevel>4</WarningLevel> |
58 | <NoWarn></NoWarn> | 64 | <NoWarn> |
65 | </NoWarn> | ||
59 | </PropertyGroup> | 66 | </PropertyGroup> |
60 | <ItemGroup> | 67 | <ItemGroup> |
61 | <Reference Include="libTerrain-BSD.dll" > | 68 | <Reference Include="libTerrain-BSD.dll"> |
62 | <HintPath>..\..\bin\libTerrain-BSD.dll</HintPath> | 69 | <HintPath>..\..\bin\libTerrain-BSD.dll</HintPath> |
63 | <Private>False</Private> | 70 | <Private>False</Private> |
64 | </Reference> | 71 | </Reference> |
65 | <Reference Include="openjpegnet.dll" > | 72 | <Reference Include="Microsoft.JScript" /> |
73 | <Reference Include="openjpegnet.dll"> | ||
66 | <HintPath>..\..\bin\openjpegnet.dll</HintPath> | 74 | <HintPath>..\..\bin\openjpegnet.dll</HintPath> |
67 | <Private>False</Private> | 75 | <Private>False</Private> |
68 | </Reference> | 76 | </Reference> |
69 | <Reference Include="System" > | 77 | <Reference Include="System"> |
70 | <HintPath>System.dll</HintPath> | 78 | <HintPath>System.dll</HintPath> |
71 | <Private>False</Private> | 79 | <Private>False</Private> |
72 | </Reference> | 80 | </Reference> |
73 | <Reference Include="System.Data" > | 81 | <Reference Include="System.Data"> |
74 | <HintPath>System.Data.dll</HintPath> | 82 | <HintPath>System.Data.dll</HintPath> |
75 | <Private>False</Private> | 83 | <Private>False</Private> |
76 | </Reference> | 84 | </Reference> |
77 | <Reference Include="System.Drawing" > | 85 | <Reference Include="System.Drawing"> |
78 | <HintPath>System.Drawing.dll</HintPath> | 86 | <HintPath>System.Drawing.dll</HintPath> |
79 | <Private>False</Private> | 87 | <Private>False</Private> |
80 | </Reference> | 88 | </Reference> |
81 | <Reference Include="System.Xml" > | 89 | <Reference Include="System.Xml"> |
82 | <HintPath>System.Xml.dll</HintPath> | 90 | <HintPath>System.Xml.dll</HintPath> |
83 | <Private>False</Private> | 91 | <Private>False</Private> |
84 | </Reference> | 92 | </Reference> |
@@ -92,6 +100,7 @@ | |||
92 | <Compile Include="Properties\AssemblyInfo.cs"> | 100 | <Compile Include="Properties\AssemblyInfo.cs"> |
93 | <SubType>Code</SubType> | 101 | <SubType>Code</SubType> |
94 | </Compile> | 102 | </Compile> |
103 | <Compile Include="TerrainFilter.cs" /> | ||
95 | </ItemGroup> | 104 | </ItemGroup> |
96 | <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> | 105 | <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> |
97 | <PropertyGroup> | 106 | <PropertyGroup> |
@@ -100,4 +109,4 @@ | |||
100 | <PostBuildEvent> | 109 | <PostBuildEvent> |
101 | </PostBuildEvent> | 110 | </PostBuildEvent> |
102 | </PropertyGroup> | 111 | </PropertyGroup> |
103 | </Project> | 112 | </Project> \ 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 | |||
48 | public class TerrainEngine | 48 | public class TerrainEngine |
49 | { | 49 | { |
50 | /// <summary> | 50 | /// <summary> |
51 | /// Plugin library for scripts | ||
52 | /// </summary> | ||
53 | public FilterHost customFilters = new FilterHost(); | ||
54 | |||
55 | /// <summary> | ||
51 | /// A [normally] 256x256 heightmap | 56 | /// A [normally] 256x256 heightmap |
52 | /// </summary> | 57 | /// </summary> |
53 | public Channel heightmap; | 58 | public Channel heightmap; |
@@ -193,8 +198,10 @@ namespace OpenSim.Terrain | |||
193 | resultText += "terrain erode aerobic <windspeed> <pickupmin> <dropmin> <carry> <rounds> <lowest>\n"; | 198 | resultText += "terrain erode aerobic <windspeed> <pickupmin> <dropmin> <carry> <rounds> <lowest>\n"; |
194 | resultText += "terrain erode thermal <talus> <rounds> <carry>\n"; | 199 | resultText += "terrain erode thermal <talus> <rounds> <carry>\n"; |
195 | resultText += "terrain multiply <val> - multiplies a terrain by <val>\n"; | 200 | resultText += "terrain multiply <val> - multiplies a terrain by <val>\n"; |
196 | resultText += "terrain revert - reverts the terrain to the stored original"; | 201 | resultText += "terrain revert - reverts the terrain to the stored original\n"; |
197 | resultText += "terrain bake - saves the current terrain into the revert map"; | 202 | resultText += "terrain bake - saves the current terrain into the revert map\n"; |
203 | resultText += "terrain csfilter <filename.cs> - loads a new filter from the specified .cs file\n"; | ||
204 | resultText += "terrain jsfilter <filename.js> - loads a new filter from the specified .js file\n"; | ||
198 | return false; | 205 | return false; |
199 | 206 | ||
200 | case "revert": | 207 | case "revert": |
@@ -285,9 +292,25 @@ namespace OpenSim.Terrain | |||
285 | } | 292 | } |
286 | break; | 293 | break; |
287 | 294 | ||
295 | case "csfilter": | ||
296 | customFilters.LoadFilterCSharp(args[1]); | ||
297 | break; | ||
298 | case "jsfilter": | ||
299 | customFilters.LoadFilterJScript(args[1]); | ||
300 | break; | ||
301 | |||
288 | default: | 302 | default: |
289 | resultText = "Unknown terrain command"; | 303 | // Run any custom registered filters |
290 | return false; | 304 | if (customFilters.filters.ContainsKey(command)) |
305 | { | ||
306 | customFilters.filters[command].Filter(heightmap, args); | ||
307 | break; | ||
308 | } | ||
309 | else | ||
310 | { | ||
311 | resultText = "Unknown terrain command"; | ||
312 | return false; | ||
313 | } | ||
291 | } | 314 | } |
292 | return true; | 315 | return true; |
293 | } | 316 | } |
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 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | using System.CodeDom.Compiler; | ||
6 | using System.CodeDom; | ||
7 | using Microsoft.CSharp; | ||
8 | using Microsoft.JScript; | ||
9 | |||
10 | using libTerrain; | ||
11 | |||
12 | namespace OpenSim.Terrain | ||
13 | { | ||
14 | public interface ITerrainFilter | ||
15 | { | ||
16 | void Filter(Channel heightmap, string[] args); | ||
17 | string Register(); | ||
18 | } | ||
19 | |||
20 | public class TestFilter : ITerrainFilter | ||
21 | { | ||
22 | public void Filter(Channel heightmap, string[] args) | ||
23 | { | ||
24 | Console.WriteLine("Hello world"); | ||
25 | } | ||
26 | |||
27 | public string Register() | ||
28 | { | ||
29 | return "demofilter"; | ||
30 | } | ||
31 | } | ||
32 | |||
33 | public class FilterHost | ||
34 | { | ||
35 | public Dictionary<string, ITerrainFilter> filters = new Dictionary<string, ITerrainFilter>(); | ||
36 | |||
37 | private void LoadFilter(ICodeCompiler compiler, string filename) | ||
38 | { | ||
39 | CompilerParameters compilerParams = new CompilerParameters(); | ||
40 | CompilerResults compilerResults; | ||
41 | compilerParams.GenerateExecutable = false; | ||
42 | compilerParams.GenerateInMemory = true; | ||
43 | compilerParams.IncludeDebugInformation = false; | ||
44 | compilerParams.ReferencedAssemblies.Add("libTerrain-BSD.dll"); | ||
45 | compilerParams.ReferencedAssemblies.Add("OpenSim.Terrain.BasicTerrain.dll"); | ||
46 | compilerParams.ReferencedAssemblies.Add("System.dll"); | ||
47 | |||
48 | compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename); | ||
49 | |||
50 | if (compilerResults.Errors.Count > 0) | ||
51 | { | ||
52 | Console.WriteLine("Compile errors:"); | ||
53 | foreach (CompilerError error in compilerResults.Errors) | ||
54 | { | ||
55 | Console.WriteLine(error.Line.ToString() + ": " + error.ErrorText.ToString()); | ||
56 | } | ||
57 | } | ||
58 | else | ||
59 | { | ||
60 | foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes()) | ||
61 | { | ||
62 | Type testInterface = pluginType.GetInterface("ITerrainFilter",true); | ||
63 | |||
64 | if (testInterface != null) | ||
65 | { | ||
66 | ITerrainFilter filter = (ITerrainFilter)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString()); | ||
67 | |||
68 | string filterName = filter.Register(); | ||
69 | Console.WriteLine("Plugin: " + filterName + " loaded."); | ||
70 | |||
71 | if (!filters.ContainsKey(filterName)) | ||
72 | { | ||
73 | filters.Add(filterName, filter); | ||
74 | } | ||
75 | else | ||
76 | { | ||
77 | filters[filterName] = filter; | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | |||
83 | } | ||
84 | |||
85 | public void LoadFilterCSharp(string filename) | ||
86 | { | ||
87 | CSharpCodeProvider compiler = new CSharpCodeProvider(); | ||
88 | LoadFilter(compiler.CreateCompiler(), filename); | ||
89 | } | ||
90 | |||
91 | public void LoadFilterJScript(string filename) | ||
92 | { | ||
93 | JScriptCodeProvider compiler = new JScriptCodeProvider(); | ||
94 | LoadFilter(compiler.CreateCompiler(), filename); | ||
95 | } | ||
96 | } | ||
97 | } | ||
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 | |||
434 | break; | 434 | break; |
435 | 435 | ||
436 | case "terrain": | 436 | case "terrain": |
437 | //string result = ""; | 437 | string result = ""; |
438 | /* if (!((World)m_localWorld).Terrain.RunTerrainCmd(cmdparams, ref result)) | 438 | for (int i = 0; i < m_localWorld.Count; i++) |
439 | { | 439 | { |
440 | m_log.Error( result); | 440 | if (!((Scene)m_localWorld[i]).Terrain.RunTerrainCmd(cmdparams, ref result)) |
441 | }*/ | 441 | { |
442 | m_log.Error(result); | ||
443 | } | ||
444 | } | ||
442 | break; | 445 | break; |
443 | 446 | ||
444 | case "shutdown": | 447 | case "shutdown": |