update module to new version

master
Christopher 2020-01-09 15:54:24 +01:00
parent 514f78e6a1
commit df000afb0d
5 changed files with 1080 additions and 1015 deletions

View File

@ -1,216 +1,217 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
<PropertyGroup> <PropertyGroup>
<ProjectType>Local</ProjectType> <ProjectType>Local</ProjectType>
<ProductVersion>14.0.23107.0</ProductVersion> <ProductVersion>14.0.23107.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D5EA1308-0000-0000-0000-000000000000}</ProjectGuid> <ProjectGuid>{D5EA1308-0000-0000-0000-000000000000}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<ApplicationIcon></ApplicationIcon> <ApplicationIcon>
<AssemblyKeyContainerName> </ApplicationIcon>
</AssemblyKeyContainerName> <AssemblyKeyContainerName>
<AssemblyName>OpenSim.Modules.Warp3DCachedImageModule</AssemblyName> </AssemblyKeyContainerName>
<DefaultClientScript>JScript</DefaultClientScript> <AssemblyName>OpenSim.Modules.Warp3DCachedImageModule</AssemblyName>
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout> <DefaultClientScript>JScript</DefaultClientScript>
<DefaultTargetSchema>IE50</DefaultTargetSchema> <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
<DelaySign>false</DelaySign> <DefaultTargetSchema>IE50</DefaultTargetSchema>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> <DelaySign>false</DelaySign>
<OutputType>Library</OutputType> <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<AppDesignerFolder></AppDesignerFolder> <OutputType>Library</OutputType>
<RootNamespace>OpenSim.Modules.Warp3DCachedImageModule</RootNamespace> <AppDesignerFolder>
<StartupObject></StartupObject> </AppDesignerFolder>
<StartArguments></StartArguments> <RootNamespace>OpenSim.Modules.Warp3DCachedImageModule</RootNamespace>
<FileUpgradeFlags> <StartupObject>
</FileUpgradeFlags> </StartupObject>
</PropertyGroup> <StartArguments>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> </StartArguments>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <FileUpgradeFlags>
<BaseAddress>285212672</BaseAddress> </FileUpgradeFlags>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> </PropertyGroup>
<ConfigurationOverrideFile> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</ConfigurationOverrideFile> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<DefineConstants>TRACE;DEBUG;</DefineConstants> <BaseAddress>285212672</BaseAddress>
<DocumentationFile></DocumentationFile> <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DebugSymbols>True</DebugSymbols> <ConfigurationOverrideFile>
<FileAlignment>4096</FileAlignment> </ConfigurationOverrideFile>
<Optimize>False</Optimize> <DefineConstants>TRACE;DEBUG;</DefineConstants>
<OutputPath>..\..\..\bin\</OutputPath> <DocumentationFile>
<RegisterForComInterop>False</RegisterForComInterop> </DocumentationFile>
<RemoveIntegerChecks>False</RemoveIntegerChecks> <DebugSymbols>True</DebugSymbols>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors> <FileAlignment>4096</FileAlignment>
<WarningLevel>4</WarningLevel> <Optimize>False</Optimize>
<NoStdLib>False</NoStdLib> <OutputPath>..\..\..\bin\</OutputPath>
<NoWarn></NoWarn> <RegisterForComInterop>False</RegisterForComInterop>
<PlatformTarget>AnyCPU</PlatformTarget> <RemoveIntegerChecks>False</RemoveIntegerChecks>
<Prefer32Bit>False</Prefer32Bit> <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup> <WarningLevel>4</WarningLevel>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <NoStdLib>False</NoStdLib>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <NoWarn>
<BaseAddress>285212672</BaseAddress> </NoWarn>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> <PlatformTarget>AnyCPU</PlatformTarget>
<ConfigurationOverrideFile> <Prefer32Bit>False</Prefer32Bit>
</ConfigurationOverrideFile> </PropertyGroup>
<DefineConstants>TRACE;</DefineConstants> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DocumentationFile></DocumentationFile> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<DebugSymbols>False</DebugSymbols> <BaseAddress>285212672</BaseAddress>
<FileAlignment>4096</FileAlignment> <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<Optimize>True</Optimize> <ConfigurationOverrideFile>
<OutputPath>..\..\..\bin\</OutputPath> </ConfigurationOverrideFile>
<RegisterForComInterop>False</RegisterForComInterop> <DefineConstants>TRACE;</DefineConstants>
<RemoveIntegerChecks>False</RemoveIntegerChecks> <DocumentationFile>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors> </DocumentationFile>
<WarningLevel>4</WarningLevel> <DebugSymbols>False</DebugSymbols>
<NoStdLib>False</NoStdLib> <FileAlignment>4096</FileAlignment>
<NoWarn></NoWarn> <Optimize>True</Optimize>
<PlatformTarget>AnyCPU</PlatformTarget> <OutputPath>..\..\..\bin\</OutputPath>
<Prefer32Bit>False</Prefer32Bit> <RegisterForComInterop>False</RegisterForComInterop>
</PropertyGroup> <RemoveIntegerChecks>False</RemoveIntegerChecks>
<ItemGroup> <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<Reference Include="Axiom.MathLib.dll" > <WarningLevel>4</WarningLevel>
<Name>Axiom.MathLib.dll</Name> <NoStdLib>False</NoStdLib>
<HintPath>..\..\bin\Axiom.MathLib.dll</HintPath> <NoWarn>
<Private>False</Private> </NoWarn>
</Reference> <PlatformTarget>AnyCPU</PlatformTarget>
<Reference Include="CSJ2K.dll" > <Prefer32Bit>False</Prefer32Bit>
<Name>CSJ2K.dll</Name> </PropertyGroup>
<HintPath>..\..\..\bin\CSJ2K.dll</HintPath> <ItemGroup>
<Private>False</Private> <Reference Include="Axiom.MathLib.dll">
</Reference> <Name>Axiom.MathLib.dll</Name>
<Reference Include="HttpServer_OpenSim.dll" > <HintPath>..\..\bin\Axiom.MathLib.dll</HintPath>
<Name>HttpServer_OpenSim.dll</Name> <Private>False</Private>
<HintPath>..\..\..\bin\HttpServer_OpenSim.dll</HintPath> </Reference>
<Private>False</Private> <Reference Include="CSJ2K.dll">
</Reference> <Name>CSJ2K.dll</Name>
<Reference Include="log4net.dll" > <HintPath>..\..\..\bin\CSJ2K.dll</HintPath>
<Name>log4net.dll</Name> <Private>False</Private>
<HintPath>..\..\..\bin\log4net.dll</HintPath> </Reference>
<Private>False</Private> <Reference Include="HttpServer_OpenSim.dll">
</Reference> <Name>HttpServer_OpenSim.dll</Name>
<Reference Include="Mono.Addins.dll" > <HintPath>..\..\..\bin\HttpServer_OpenSim.dll</HintPath>
<Name>Mono.Addins.dll</Name> <Private>False</Private>
<HintPath>..\..\..\bin\Mono.Addins.dll</HintPath> </Reference>
<Private>False</Private> <Reference Include="log4net.dll">
</Reference> <Name>log4net.dll</Name>
<Reference Include="Nini.dll" > <HintPath>..\..\..\bin\log4net.dll</HintPath>
<Name>Nini.dll</Name> <Private>False</Private>
<HintPath>..\..\..\bin\Nini.dll</HintPath> </Reference>
<Private>False</Private> <Reference Include="Mono.Addins.dll">
</Reference> <Name>Mono.Addins.dll</Name>
<Reference Include="OpenMetaverse.dll" > <HintPath>..\..\..\bin\Mono.Addins.dll</HintPath>
<Name>OpenMetaverse.dll</Name> <Private>False</Private>
<HintPath>..\..\..\bin\OpenMetaverse.dll</HintPath> </Reference>
<Private>False</Private> <Reference Include="Nini.dll">
</Reference> <Name>Nini.dll</Name>
<Reference Include="OpenMetaverse.StructuredData.dll" > <HintPath>..\..\..\bin\Nini.dll</HintPath>
<Name>OpenMetaverse.StructuredData.dll</Name> <Private>False</Private>
<HintPath>..\..\..\bin\OpenMetaverse.StructuredData.dll</HintPath> </Reference>
<Private>False</Private> <Reference Include="OpenMetaverse.dll">
</Reference> <Name>OpenMetaverse.dll</Name>
<Reference Include="OpenMetaverseTypes.dll" > <HintPath>..\..\..\bin\OpenMetaverse.dll</HintPath>
<Name>OpenMetaverseTypes.dll</Name> <Private>False</Private>
<HintPath>..\..\..\bin\OpenMetaverseTypes.dll</HintPath> </Reference>
<Private>False</Private> <Reference Include="OpenMetaverse.StructuredData.dll">
</Reference> <Name>OpenMetaverse.StructuredData.dll</Name>
<Reference Include="OpenSim.Region.PhysicsModules.SharedBase.dll" > <HintPath>..\..\..\bin\OpenMetaverse.StructuredData.dll</HintPath>
<Name>OpenSim.Region.PhysicsModules.SharedBase.dll</Name> <Private>False</Private>
<HintPath>..\..\..\bin\OpenSim.Region.PhysicsModules.SharedBase.dll</HintPath> </Reference>
<Private>False</Private> <Reference Include="OpenMetaverseTypes.dll">
</Reference> <Name>OpenMetaverseTypes.dll</Name>
<Reference Include="System" > <HintPath>..\..\..\bin\OpenMetaverseTypes.dll</HintPath>
<Name>System</Name> <Private>False</Private>
<Private>False</Private> </Reference>
</Reference> <Reference Include="OpenSim.Region.PhysicsModules.SharedBase.dll">
<Reference Include="System.Drawing" > <Name>OpenSim.Region.PhysicsModules.SharedBase.dll</Name>
<Name>System.Drawing</Name> <HintPath>..\..\..\bin\OpenSim.Region.PhysicsModules.SharedBase.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System.Runtime.Remoting" > <Reference Include="System">
<Name>System.Runtime.Remoting</Name> <Name>System</Name>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System.Xml" > <Reference Include="System.Drawing">
<Name>System.Xml</Name> <Name>System.Drawing</Name>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="Warp3D.dll" > <Reference Include="System.Runtime.Remoting">
<Name>Warp3D.dll</Name> <Name>System.Runtime.Remoting</Name>
<HintPath>..\..\..\bin\Warp3D.dll</HintPath> <Private>False</Private>
<Private>False</Private> </Reference>
</Reference> <Reference Include="System.Xml">
<Reference Include="XMLRPC.dll" > <Name>System.Xml</Name>
<Name>XMLRPC.dll</Name> <Private>False</Private>
<HintPath>..\..\..\bin\XMLRPC.dll</HintPath> </Reference>
<Private>False</Private> <Reference Include="Warp3D.dll">
</Reference> <Name>Warp3D.dll</Name>
</ItemGroup> <HintPath>..\..\..\bin\Warp3D.dll</HintPath>
<ItemGroup> <Private>False</Private>
<ProjectReference Include="..\..\..\OpenSim\Data\OpenSim.Data.csproj"> </Reference>
<Name>OpenSim.Data</Name> <Reference Include="XMLRPC.dll">
<Project>{7E218E2D-0000-0000-0000-000000000000}</Project> <Name>XMLRPC.dll</Name>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> <HintPath>..\..\..\bin\XMLRPC.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </Reference>
<ProjectReference Include="..\..\..\OpenSim\Framework\OpenSim.Framework.csproj">
<Name>OpenSim.Framework</Name>
<Project>{BCCDBB55-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\Console\OpenSim.Framework.Console.csproj">
<Name>OpenSim.Framework.Console</Name>
<Project>{0ED8EBE8-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\Servers\OpenSim.Framework.Servers.csproj">
<Name>OpenSim.Framework.Servers</Name>
<Project>{726D540D-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\Servers\HttpServer\OpenSim.Framework.Servers.HttpServer.csproj">
<Name>OpenSim.Framework.Servers.HttpServer</Name>
<Project>{159EC5C2-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Region\Framework\OpenSim.Region.Framework.csproj">
<Name>OpenSim.Region.Framework</Name>
<Project>{C98F6D97-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Server\Base\OpenSim.Server.Base.csproj">
<Name>OpenSim.Server.Base</Name>
<Project>{2E0569BB-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Services\Interfaces\OpenSim.Services.Interfaces.csproj">
<Name>OpenSim.Services.Interfaces</Name>
<Project>{08ECE473-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Perlin.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="TerrainSplat.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Viewport.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Warp3DImageModule.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup>
<PropertyGroup> <ProjectReference Include="..\..\..\OpenSim\Data\OpenSim.Data.csproj">
<PreBuildEvent> <Name>OpenSim.Data</Name>
</PreBuildEvent> <Project>{7E218E2D-0000-0000-0000-000000000000}</Project>
<PostBuildEvent> <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
</PostBuildEvent> <Private>False</Private>
</PropertyGroup> </ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\OpenSim.Framework.csproj">
<Name>OpenSim.Framework</Name>
<Project>{BCCDBB55-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\Console\OpenSim.Framework.Console.csproj">
<Name>OpenSim.Framework.Console</Name>
<Project>{0ED8EBE8-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\Servers\OpenSim.Framework.Servers.csproj">
<Name>OpenSim.Framework.Servers</Name>
<Project>{726D540D-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\Servers\HttpServer\OpenSim.Framework.Servers.HttpServer.csproj">
<Name>OpenSim.Framework.Servers.HttpServer</Name>
<Project>{159EC5C2-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Region\Framework\OpenSim.Region.Framework.csproj">
<Name>OpenSim.Region.Framework</Name>
<Project>{C98F6D97-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Server\Base\OpenSim.Server.Base.csproj">
<Name>OpenSim.Server.Base</Name>
<Project>{2E0569BB-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Services\Interfaces\OpenSim.Services.Interfaces.csproj">
<Name>OpenSim.Services.Interfaces</Name>
<Project>{08ECE473-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Perlin.cs" />
<Compile Include="TerrainSplat.cs" />
<Compile Include="Warp3DImageModule.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project> </Project>

View File

@ -103,41 +103,39 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
public static float noise2(float x, float y) public static float noise2(float x, float y)
{ {
int bx0, bx1, by0, by1, b00, b10, b01, b11; int bx, by, b00, b10, b01, b11;
float rx0, rx1, ry0, ry1, sx, sy, a, b, t, u, v; float rx0, rx1, ry0, ry1, sx, sy, a, b, t, u, v;
int i, j; int i, j;
t = x + N; t = x + N;
bx0 = ((int)t) & BM;
bx1 = (bx0 + 1) & BM;
rx0 = t - (int)t; rx0 = t - (int)t;
rx1 = rx0 - 1f; bx = ((int)t) & BM;
i = p[bx];
bx = (bx + 1) & BM;
j = p[bx];
t = y + N; t = y + N;
by0 = ((int)t) & BM;
by1 = (by0 + 1) & BM;
ry0 = t - (int)t; ry0 = t - (int)t;
ry1 = ry0 - 1f; by = ((int)t) & BM;
b00 = p[i + by];
b10 = p[j + by];
i = p[bx0]; by = (by + 1) & BM;
j = p[bx1]; b01 = p[i + by];
b11 = p[j + by];
b00 = p[i + by0];
b10 = p[j + by0];
b01 = p[i + by1];
b11 = p[j + by1];
sx = s_curve(rx0); sx = s_curve(rx0);
sy = s_curve(ry0);
u = rx0 * g2[b00, 0] + ry0 * g2[b00, 1]; u = rx0 * g2[b00, 0] + ry0 * g2[b00, 1];
rx1 = rx0 - 1f;
v = rx1 * g2[b10, 0] + ry0 * g2[b10, 1]; v = rx1 * g2[b10, 0] + ry0 * g2[b10, 1];
a = Utils.Lerp(u, v, sx); a = Utils.Lerp(u, v, sx);
ry1 = ry0 - 1f;
u = rx0 * g2[b01, 0] + ry1 * g2[b01, 1]; u = rx0 * g2[b01, 0] + ry1 * g2[b01, 1];
v = rx1 * g2[b11, 0] + ry1 * g2[b11, 1]; v = rx1 * g2[b11, 0] + ry1 * g2[b11, 1];
b = Utils.Lerp(u, v, sx); b = Utils.Lerp(u, v, sx);
sy = s_curve(ry0);
return Utils.Lerp(a, b, sy); return Utils.Lerp(a, b, sy);
} }
@ -202,12 +200,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
public static float turbulence1(float x, float freq) public static float turbulence1(float x, float freq)
{ {
float t; float t;
float v;
for (t = 0f; freq >= 1f; freq *= 0.5f) for (t = 0f; freq >= 1f; freq *= 0.5f)
{ {
v = freq * x; t += noise1(freq * x) / freq;
t += noise1(v) / freq;
} }
return t; return t;
} }
@ -215,28 +211,20 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
public static float turbulence2(float x, float y, float freq) public static float turbulence2(float x, float y, float freq)
{ {
float t; float t;
Vector2 vec;
for (t = 0f; freq >= 1f; freq *= 0.5f) for (t = 0f; freq >= 1f; freq *= 0.5f)
{ t += noise2(freq * x, freq * y) / freq;
vec.X = freq * x;
vec.Y = freq * y;
t += noise2(vec.X, vec.Y) / freq;
}
return t; return t;
} }
public static float turbulence3(float x, float y, float z, float freq) public static float turbulence3(float x, float y, float z, float freq)
{ {
float t; float t;
Vector3 vec;
for (t = 0f; freq >= 1f; freq *= 0.5f) for (t = 0f; freq >= 1f; freq *= 0.5f)
{ {
vec.X = freq * x; t += noise3(freq * x, freq * y, freq * z) / freq;
vec.Y = freq * y;
vec.Z = freq * z;
t += noise3(vec.X, vec.Y, vec.Z) / freq;
} }
return t; return t;
} }
@ -244,23 +232,28 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
private static void normalize2(float[,] v, int i) private static void normalize2(float[,] v, int i)
{ {
float s; float s;
float a = v[i, 0];
float b = v[i, 1];
s = (float)Math.Sqrt(v[i, 0] * v[i, 0] + v[i, 1] * v[i, 1]); s = (float)Math.Sqrt(a * a + b * b);
s = 1.0f / s; s = 1.0f / s;
v[i, 0] = v[i, 0] * s; v[i, 0] = a * s;
v[i, 1] = v[i, 1] * s; v[i, 1] = b * s;
} }
private static void normalize3(float[,] v, int i) private static void normalize3(float[,] v, int i)
{ {
float s; float s;
float a = v[i, 0];
float b = v[i, 1];
float c = v[i, 2];
s = (float)Math.Sqrt(v[i, 0] * v[i, 0] + v[i, 1] * v[i, 1] + v[i, 2] * v[i, 2]); s = (float)Math.Sqrt(a * a + b * b + c * c);
s = 1.0f / s; s = 1.0f / s;
v[i, 0] = v[i, 0] * s; v[i, 0] = a * s;
v[i, 1] = v[i, 1] * s; v[i, 1] = b * s;
v[i, 2] = v[i, 2] * s; v[i, 2] = c * s;
} }
private static float s_curve(float t) private static float s_curve(float t)

View File

@ -80,9 +80,12 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
/// Note we create a 256x256 dimension texture even if the actual terrain is larger. /// Note we create a 256x256 dimension texture even if the actual terrain is larger.
/// </remarks> /// </remarks>
public static Bitmap Splat(ITerrainChannel terrain, public static Bitmap Splat(ITerrainChannel terrain, UUID[] textureIDs,
UUID[] textureIDs, float[] startHeights, float[] heightRanges, float[] startHeights, float[] heightRanges,
Vector3d regionPosition, IAssetService assetService, bool textureTerrain) uint regionPositionX, uint regionPositionY,
IAssetService assetService, IJ2KDecoder decoder,
bool textureTerrain, bool averagetextureTerrain,
int twidth, int theight)
{ {
Debug.Assert(textureIDs.Length == 4); Debug.Assert(textureIDs.Length == 4);
Debug.Assert(startHeights.Length == 4); Debug.Assert(startHeights.Length == 4);
@ -90,70 +93,80 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
Bitmap[] detailTexture = new Bitmap[4]; Bitmap[] detailTexture = new Bitmap[4];
byte[] mapColorsRed = new byte[4];
byte[] mapColorsGreen = new byte[4];
byte[] mapColorsBlue = new byte[4];
bool usecolors = false;
if (textureTerrain) if (textureTerrain)
{ {
// Swap empty terrain textureIDs with default IDs // Swap empty terrain textureIDs with default IDs
for (int i = 0; i < textureIDs.Length; i++) for(int i = 0; i < textureIDs.Length; i++)
{ {
if (textureIDs[i] == UUID.Zero) if(textureIDs[i] == UUID.Zero)
textureIDs[i] = DEFAULT_TERRAIN_DETAIL[i]; textureIDs[i] = DEFAULT_TERRAIN_DETAIL[i];
} }
#region Texture Fetching #region Texture Fetching
if (assetService != null) if(assetService != null)
{ {
for (int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{ {
AssetBase asset; AssetBase asset = null;
UUID cacheID = UUID.Combine(TERRAIN_CACHE_MAGIC, textureIDs[i]);
// asset cache indexes are strings
string cacheName ="MAP-Patch" + textureIDs[i].ToString();
// Try to fetch a cached copy of the decoded/resized version of this texture // Try to fetch a cached copy of the decoded/resized version of this texture
asset = assetService.GetCached(cacheID.ToString()); asset = assetService.GetCached(cacheName);
if (asset != null) if(asset != null)
{ {
try try
{ {
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(asset.Data)) using(System.IO.MemoryStream stream = new System.IO.MemoryStream(asset.Data))
detailTexture[i] = (Bitmap)Image.FromStream(stream); detailTexture[i] = (Bitmap)Image.FromStream(stream);
if(detailTexture[i].PixelFormat != PixelFormat.Format24bppRgb ||
detailTexture[i].Width != 16 || detailTexture[i].Height != 16)
{
detailTexture[i].Dispose();
detailTexture[i] = null;
}
} }
catch (Exception ex) catch(Exception ex)
{ {
m_log.Warn("Failed to decode cached terrain texture " + cacheID + m_log.Warn("Failed to decode cached terrain patch texture" + textureIDs[i] + "): " + ex.Message);
" (textureID: " + textureIDs[i] + "): " + ex.Message);
} }
} }
if (detailTexture[i] == null) if(detailTexture[i] == null)
{ {
// Try to fetch the original JPEG2000 texture, resize if needed, and cache as PNG // Try to fetch the original JPEG2000 texture, resize if needed, and cache as PNG
asset = assetService.Get(textureIDs[i].ToString()); asset = assetService.Get(textureIDs[i].ToString());
if (asset != null) if(asset != null)
{ {
// m_log.DebugFormat( try
// "[TERRAIN SPLAT]: Got cached original JPEG2000 terrain texture {0} {1}", i, asset.ID); {
detailTexture[i] = (Bitmap)decoder.DecodeToImage(asset.Data);
try { detailTexture[i] = (Bitmap)CSJ2K.J2kImage.FromBytes(asset.Data); } }
catch (Exception ex) catch(Exception ex)
{ {
m_log.Warn("Failed to decode terrain texture " + asset.ID + ": " + ex.Message); m_log.Warn("Failed to decode terrain texture " + asset.ID + ": " + ex.Message);
} }
} }
if (detailTexture[i] != null) if(detailTexture[i] != null)
{ {
// Make sure this texture is the correct size, otherwise resize if(detailTexture[i].PixelFormat != PixelFormat.Format24bppRgb ||
if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256) detailTexture[i].Width != 16 || detailTexture[i].Height != 16)
{ using(Bitmap origBitmap = detailTexture[i])
using (Bitmap origBitmap = detailTexture[i]) detailTexture[i] = Util.ResizeImageSolid(origBitmap, 16, 16);
{
detailTexture[i] = ImageUtils.ResizeImage(origBitmap, 256, 256);
}
}
// Save the decoded and resized texture to the cache // Save the decoded and resized texture to the cache
byte[] data; byte[] data;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) using(System.IO.MemoryStream stream = new System.IO.MemoryStream())
{ {
detailTexture[i].Save(stream, ImageFormat.Png); detailTexture[i].Save(stream, ImageFormat.Png);
data = stream.ToArray(); data = stream.ToArray();
@ -165,8 +178,8 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
Data = data, Data = data,
Description = "PNG", Description = "PNG",
Flags = AssetFlags.Collectable, Flags = AssetFlags.Collectable,
FullID = cacheID, FullID = UUID.Zero,
ID = cacheID.ToString(), ID = cacheName,
Local = true, Local = true,
Name = String.Empty, Name = String.Empty,
Temporary = true, Temporary = true,
@ -180,209 +193,278 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
} }
#endregion Texture Fetching #endregion Texture Fetching
} if(averagetextureTerrain)
// Fill in any missing textures with a solid color
for (int i = 0; i < 4; i++)
{
if (detailTexture[i] == null)
{ {
m_log.DebugFormat("{0} Missing terrain texture for layer {1}. Filling with solid default color", for(int t = 0; t < 4; t++)
LogHeader, i);
// Create a solid color texture for this layer
detailTexture[i] = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
using (Graphics gfx = Graphics.FromImage(detailTexture[i]))
{ {
using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i])) usecolors = true;
gfx.FillRectangle(brush, 0, 0, 256, 256); if(detailTexture[t] == null)
{
mapColorsRed[t] = DEFAULT_TERRAIN_COLOR[t].R;
mapColorsGreen[t] = DEFAULT_TERRAIN_COLOR[t].G;
mapColorsBlue[t] = DEFAULT_TERRAIN_COLOR[t].B;
continue;
}
int npixeis = 0;
int cR = 0;
int cG = 0;
int cB = 0;
BitmapData bmdata = detailTexture[t].LockBits(new Rectangle(0, 0, 16, 16),
ImageLockMode.ReadOnly, detailTexture[t].PixelFormat);
npixeis = bmdata.Height * bmdata.Width;
int ylen = bmdata.Height * bmdata.Stride;
unsafe
{
for(int y = 0; y < ylen; y += bmdata.Stride)
{
byte* ptrc = (byte*)bmdata.Scan0 + y;
for(int x = 0 ; x < bmdata.Width; ++x)
{
cR += *(ptrc++);
cG += *(ptrc++);
cB += *(ptrc++);
}
}
}
detailTexture[t].UnlockBits(bmdata);
detailTexture[t].Dispose();
mapColorsRed[t] = (byte)Util.Clamp(cR / npixeis, 0 , 255);
mapColorsGreen[t] = (byte)Util.Clamp(cG / npixeis, 0 , 255);
mapColorsBlue[t] = (byte)Util.Clamp(cB / npixeis, 0 , 255);
} }
} }
else else
{ {
if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256) // Fill in any missing textures with a solid color
for(int i = 0; i < 4; i++)
{ {
detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256); if(detailTexture[i] == null)
{
m_log.DebugFormat("{0} Missing terrain texture for layer {1}. Filling with solid default color", LogHeader, i);
// Create a solid color texture for this layer
detailTexture[i] = new Bitmap(16, 16, PixelFormat.Format24bppRgb);
using(Graphics gfx = Graphics.FromImage(detailTexture[i]))
{
using(SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i]))
gfx.FillRectangle(brush, 0, 0, 16, 16);
}
}
else
{
if(detailTexture[i].Width != 16 || detailTexture[i].Height != 16)
{
using(Bitmap origBitmap = detailTexture[i])
detailTexture[i] = Util.ResizeImageSolid(origBitmap, 16, 16);
}
}
} }
} }
} }
else
{
usecolors = true;
for(int t = 0; t < 4; t++)
{
mapColorsRed[t] = DEFAULT_TERRAIN_COLOR[t].R;
mapColorsGreen[t] = DEFAULT_TERRAIN_COLOR[t].G;
mapColorsBlue[t] = DEFAULT_TERRAIN_COLOR[t].B;
}
}
#region Layer Map #region Layer Map
float[,] layermap = new float[256, 256]; float xFactor = terrain.Width / twidth;
float yFactor = terrain.Height / theight;
// Scale difference between actual region size and the 256 texture being created
int xFactor = terrain.Width / 256;
int yFactor = terrain.Height / 256;
// Create 'layermap' where each value is the fractional layer number to place
// at that point. For instance, a value of 1.345 gives the blending of
// layer 1 and layer 2 for that point.
for (int y = 0; y < 256; y++)
{
for (int x = 0; x < 256; x++)
{
float height = (float)terrain[x * xFactor, y * yFactor];
float pctX = (float)x / 255f;
float pctY = (float)y / 255f;
// Use bilinear interpolation between the four corners of start height and
// height range to select the current values at this position
float startHeight = ImageUtils.Bilinear(
startHeights[0],
startHeights[2],
startHeights[1],
startHeights[3],
pctX, pctY);
startHeight = Utils.Clamp(startHeight, 0f, 255f);
float heightRange = ImageUtils.Bilinear(
heightRanges[0],
heightRanges[2],
heightRanges[1],
heightRanges[3],
pctX, pctY);
heightRange = Utils.Clamp(heightRange, 0f, 255f);
// Generate two frequencies of perlin noise based on our global position
// The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
Vector3 vec = new Vector3
(
((float)regionPosition.X + (x * xFactor)) * 0.20319f,
((float)regionPosition.Y + (y * yFactor)) * 0.20319f,
height * 0.25f
);
float lowFreq = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 6.5f;
float highFreq = Perlin.turbulence2(vec.X, vec.Y, 2f) * 2.25f;
float noise = (lowFreq + highFreq) * 2f;
// Combine the current height, generated noise, start height, and height range parameters, then scale all of it
float layer = ((height + noise - startHeight) / heightRange) * 4f;
if (Single.IsNaN(layer))
layer = 0f;
layermap[x, y] = Utils.Clamp(layer, 0f, 3f);
}
}
#endregion Layer Map #endregion Layer Map
#region Texture Compositing #region Texture Compositing
Bitmap output = new Bitmap(256, 256, PixelFormat.Format24bppRgb); Bitmap output = new Bitmap(twidth, theight, PixelFormat.Format24bppRgb);
BitmapData outputData = output.LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb); BitmapData outputData = output.LockBits(new Rectangle(0, 0, twidth, theight), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
// Unsafe work as we lock down the source textures for quicker access and access the // Unsafe work as we lock down the source textures for quicker access and access the
// pixel data directly // pixel data directly
unsafe float invtwitdthMinus1 = 1.0f / (twidth - 1);
float invtheightMinus1 = 1.0f / (theight - 1);
int ty;
int tx;
float pctx;
float pcty;
float height;
float layer;
float layerDiff;
int l0;
int l1;
uint yglobalpos;
if(usecolors)
{ {
// Get handles to all of the texture data arrays float a;
BitmapData[] datas = new BitmapData[] float b;
unsafe
{ {
detailTexture[0].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat), byte* ptrO;
detailTexture[1].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat), for(int y = 0; y < theight; ++y)
detailTexture[2].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat),
detailTexture[3].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
};
// Compute size of each pixel data (used to address into the pixel data array)
int[] comps = new int[]
{
(datas[0].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
(datas[1].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
(datas[2].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
(datas[3].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3
};
for (int y = 0; y < 256; y++)
{
for (int x = 0; x < 256; x++)
{ {
float layer = layermap[x, y]; pcty = y * invtheightMinus1;
ptrO = (byte*)outputData.Scan0 + y * outputData.Stride;
ty = (int)(y * yFactor);
yglobalpos = (uint)ty + regionPositionY;
// Select two textures for(int x = 0; x < twidth; ++x)
int l0 = (int)Math.Floor(layer); {
int l1 = Math.Min(l0 + 1, 3); tx = (int)(x * xFactor);
pctx = x * invtwitdthMinus1;
height = (float)terrain[tx, ty];
layer = getLayerTex(height, pctx, pcty,
(uint)tx + regionPositionX, yglobalpos,
startHeights, heightRanges);
byte* ptrA = (byte*)datas[l0].Scan0 + y * datas[l0].Stride + x * comps[l0]; // Select two textures
byte* ptrB = (byte*)datas[l1].Scan0 + y * datas[l1].Stride + x * comps[l1]; l0 = (int)layer;
byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3; l1 = Math.Min(l0 + 1, 3);
float aB = *(ptrA + 0); layerDiff = layer - l0;
float aG = *(ptrA + 1);
float aR = *(ptrA + 2);
float bB = *(ptrB + 0); a = mapColorsRed[l0];
float bG = *(ptrB + 1); b = mapColorsRed[l1];
float bR = *(ptrB + 2); *(ptrO++) = (byte)(a + layerDiff * (b - a));
float layerDiff = layer - l0; a = mapColorsGreen[l0];
b = mapColorsGreen[l1];
*(ptrO++) = (byte)(a + layerDiff * (b - a));
// Interpolate between the two selected textures a = mapColorsBlue[l0];
*(ptrO + 0) = (byte)Math.Floor(aB + layerDiff * (bB - aB)); b = mapColorsBlue[l1];
*(ptrO + 1) = (byte)Math.Floor(aG + layerDiff * (bG - aG)); *(ptrO++) = (byte)(a + layerDiff * (b - a));
*(ptrO + 2) = (byte)Math.Floor(aR + layerDiff * (bR - aR)); }
} }
} }
for (int i = 0; i < detailTexture.Length; i++)
detailTexture[i].UnlockBits(datas[i]);
} }
else
{
float aB;
float aG;
float aR;
float bB;
float bG;
float bR;
for (int i = 0; i < detailTexture.Length; i++) unsafe
if (detailTexture[i] != null) {
detailTexture[i].Dispose(); // Get handles to all of the texture data arrays
BitmapData[] datas = new BitmapData[]
{
detailTexture[0].LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat),
detailTexture[1].LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat),
detailTexture[2].LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat),
detailTexture[3].LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
};
byte* ptr;
byte* ptrO;
for(int y = 0; y < theight; y++)
{
pcty = y * invtheightMinus1;
int ypatch = ((int)(y * yFactor) & 0x0f) * datas[0].Stride;
ptrO = (byte*)outputData.Scan0 + y * outputData.Stride;
ty = (int)(y * yFactor);
yglobalpos = (uint)ty + regionPositionY;
for(int x = 0; x < twidth; x++)
{
tx = (int)(x * xFactor);
pctx = x * invtwitdthMinus1;
height = (float)terrain[tx, ty];
layer = getLayerTex(height, pctx, pcty,
(uint)tx + regionPositionX, yglobalpos,
startHeights, heightRanges);
// Select two textures
l0 = (int)layer;
layerDiff = layer - l0;
int patchOffset = (tx & 0x0f) * 3 + ypatch;
ptr = (byte*)datas[l0].Scan0 + patchOffset;
aB = *(ptr++);
aG = *(ptr++);
aR = *(ptr);
l1 = Math.Min(l0 + 1, 3);
ptr = (byte*)datas[l1].Scan0 + patchOffset;
bB = *(ptr++);
bG = *(ptr++);
bR = *(ptr);
// Interpolate between the two selected textures
*(ptrO++) = (byte)(aB + layerDiff * (bB - aB));
*(ptrO++) = (byte)(aG + layerDiff * (bG - aG));
*(ptrO++) = (byte)(aR + layerDiff * (bR - aR));
}
}
for(int i = 0; i < detailTexture.Length; i++)
detailTexture[i].UnlockBits(datas[i]);
}
for(int i = 0; i < detailTexture.Length; i++)
if(detailTexture[i] != null)
detailTexture[i].Dispose();
}
output.UnlockBits(outputData); output.UnlockBits(outputData);
// We generated the texture upside down, so flip it //output.Save("terr.png",ImageFormat.Png);
output.RotateFlip(RotateFlipType.RotateNoneFlipY);
#endregion Texture Compositing #endregion Texture Compositing
return output; return output;
} }
public static Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight) [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
private static float getLayerTex(float height, float pctX, float pctY, uint X, uint Y,
float[] startHeights, float[] heightRanges)
{ {
m_log.DebugFormat("{0} ResizeBitmap. From <{1},{2}> to <{3},{4}>", // Use bilinear interpolation between the four corners of start height and
LogHeader, b.Width, b.Height, nWidth, nHeight); // height range to select the current values at this position
Bitmap result = new Bitmap(nWidth, nHeight); float startHeight = ImageUtils.Bilinear(
using (Graphics g = Graphics.FromImage(result)) startHeights[0], startHeights[2],
g.DrawImage(b, 0, 0, nWidth, nHeight); startHeights[1], startHeights[3],
b.Dispose(); pctX, pctY);
return result; if (float.IsNaN(startHeight))
} return 0;
public static Bitmap SplatSimple(float[] heightmap)
{
const float BASE_HSV_H = 93f / 360f;
const float BASE_HSV_S = 44f / 100f;
const float BASE_HSV_V = 34f / 100f;
Bitmap img = new Bitmap(256, 256); startHeight = Utils.Clamp(startHeight, 0f, 255f);
BitmapData bitmapData = img.LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
unsafe float heightRange = ImageUtils.Bilinear(
{ heightRanges[0], heightRanges[2],
for (int y = 255; y >= 0; y--) heightRanges[1], heightRanges[3],
{ pctX, pctY);
for (int x = 0; x < 256; x++) heightRange = Utils.Clamp(heightRange, 0f, 255f);
{ if(heightRange == 0f || float.IsNaN(heightRange))
float normHeight = heightmap[y * 256 + x] / 255f; return 0;
normHeight = Utils.Clamp(normHeight, BASE_HSV_V, 1.0f);
Color4 color = Color4.FromHSV(BASE_HSV_H, BASE_HSV_S, normHeight); // Generate two frequencies of perlin noise based on our global position
// The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
float sX = X * 0.20319f;
float sY = Y * 0.20319f;
byte* ptr = (byte*)bitmapData.Scan0 + y * bitmapData.Stride + x * 3; float noise = Perlin.noise2(sX * 0.222222f, sY * 0.222222f) * 13.0f;
*(ptr + 0) = (byte)(color.B * 255f); noise += Perlin.turbulence2(sX, sY, 2f) * 4.5f;
*(ptr + 1) = (byte)(color.G * 255f);
*(ptr + 2) = (byte)(color.R * 255f);
}
}
}
img.UnlockBits(bitmapData); // Combine the current height, generated noise, start height, and height range parameters, then scale all of it
return img; float layer = ((height + noise - startHeight) / heightRange) * 4f;
return Utils.Clamp(layer, 0f, 3f);
} }
} }
} }

View File

@ -1,165 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Drawing;
using OpenMetaverse;
namespace OpenSim.Region.CoreModules.World.Warp3DMap
{
public class Viewport
{
private const float DEG_TO_RAD = (float)Math.PI / 180f;
private static readonly Vector3 UP_DIRECTION = Vector3.UnitZ;
public Vector3 Position;
public Vector3 LookDirection;
public float FieldOfView;
public float NearPlaneDistance;
public float FarPlaneDistance;
public int Width;
public int Height;
public bool Orthographic;
public float OrthoWindowWidth;
public float OrthoWindowHeight;
public Viewport(Vector3 position, Vector3 lookDirection, float fieldOfView, float farPlaneDist, float nearPlaneDist, int width, int height)
{
// Perspective projection mode
Position = position;
LookDirection = lookDirection;
FieldOfView = fieldOfView;
FarPlaneDistance = farPlaneDist;
NearPlaneDistance = nearPlaneDist;
Width = width;
Height = height;
}
public Viewport(Vector3 position, Vector3 lookDirection, float farPlaneDist, float nearPlaneDist, int width, int height, float orthoWindowWidth, float orthoWindowHeight)
{
// Orthographic projection mode
Position = position;
LookDirection = lookDirection;
FarPlaneDistance = farPlaneDist;
NearPlaneDistance = nearPlaneDist;
Width = width;
Height = height;
OrthoWindowWidth = orthoWindowWidth;
OrthoWindowHeight = orthoWindowHeight;
Orthographic = true;
}
public Point VectorToScreen(Vector3 v)
{
Matrix4 m = GetWorldToViewportMatrix();
Vector3 screenPoint = v * m;
return new Point((int)screenPoint.X, (int)screenPoint.Y);
}
public Matrix4 GetWorldToViewportMatrix()
{
Matrix4 result = GetViewMatrix();
result *= GetPerspectiveProjectionMatrix();
result *= GetViewportMatrix();
return result;
}
public Matrix4 GetViewMatrix()
{
Vector3 zAxis = -LookDirection;
zAxis.Normalize();
Vector3 xAxis = Vector3.Cross(UP_DIRECTION, zAxis);
xAxis.Normalize();
Vector3 yAxis = Vector3.Cross(zAxis, xAxis);
Vector3 position = Position;
float offsetX = -Vector3.Dot(xAxis, position);
float offsetY = -Vector3.Dot(yAxis, position);
float offsetZ = -Vector3.Dot(zAxis, position);
return new Matrix4(
xAxis.X, yAxis.X, zAxis.X, 0f,
xAxis.Y, yAxis.Y, zAxis.Y, 0f,
xAxis.Z, yAxis.Z, zAxis.Z, 0f,
offsetX, offsetY, offsetZ, 1f);
}
public Matrix4 GetPerspectiveProjectionMatrix()
{
float aspectRatio = (float)Width / (float)Height;
float hFoV = FieldOfView * DEG_TO_RAD;
float zn = NearPlaneDistance;
float zf = FarPlaneDistance;
float xScale = 1f / (float)Math.Tan(hFoV / 2f);
float yScale = aspectRatio * xScale;
float m33 = (zf == double.PositiveInfinity) ? -1 : (zf / (zn - zf));
float m43 = zn * m33;
return new Matrix4(
xScale, 0f, 0f, 0f,
0f, yScale, 0f, 0f,
0f, 0f, m33, -1f,
0f, 0f, m43, 0f);
}
public Matrix4 GetOrthographicProjectionMatrix(float aspectRatio)
{
float w = Width;
float h = Height;
float zn = NearPlaneDistance;
float zf = FarPlaneDistance;
float m33 = 1 / (zn - zf);
float m43 = zn * m33;
return new Matrix4(
2f / w, 0f, 0f, 0f,
0f, 2f / h, 0f, 0f,
0f, 0f, m33, 0f,
0f, 0f, m43, 1f);
}
public Matrix4 GetViewportMatrix()
{
float scaleX = (float)Width * 0.5f;
float scaleY = (float)Height * 0.5f;
float offsetX = 0f + scaleX;
float offsetY = 0f + scaleY;
return new Matrix4(
scaleX, 0f, 0f, 0f,
0f, -scaleY, 0f, 0f,
0f, 0f, 1f, 0f,
offsetX, offsetY, 0f, 1f);
}
}
}

File diff suppressed because it is too large Load Diff