Managed editable terrain manager [Updated October 10]

lilljohan

09-01-2008 15:52:37

A .NET wrapper over Editable Terrain Manager, it is licensed under the zlib license and compiled against .NET 3.5 and Mogre 1.4.8

Download the latest version

Installation and usage
Add MET.dll to your projects references. You will also need EditableTerrainManager(_d).dll both files
are located in Binaries\Debug(Release)

To run the sample you will need to copy the appropriate dll files from your MOgre directory.

Compiling
Download the Editable Terrain Manager sources and place it in Dependencies.
Reconfigure ETM to link against Mogre headers / libraries
Rebuild ETM
Build MET.

History
October 10 2008
-- Cleaned up, recompiled - both debug and release works.
July 26 2008
-- Recompiled against Mogre 1.4.8
Jan 12 2008
-- Another small patch by Kerion, this one adds Brush[x, y] and
TerrainInfo[x, y] indexers
Jan 11 2008
-- Fix by Kerion to get correct referencing to ET::TerrainInfo*
-- GetTerrainInfo renamed to TerrainInfo
Jan 09 2008
- -MET was released

Kerion

09-01-2008 15:58:13

Well dang it, I was literally JUST working on this. Thanks for saving me the time :D I have it about half-written too, and it looks almost exactly like your code. What a small world.

Thanks for this! If I make any changes/fixes, I'll submit them back to you.

Kerion

09-01-2008 16:13:30

P.S. if I can even get this DL'ed, do you mind if I re-host it for you? Because frankly, your server sucks from the United States. The download keeps stopping halfway through and even when it is moving it's going less then 8 k/s.

lilljohan

09-01-2008 16:21:22

Small world indeed =)

8 kb/s that's quite a difference from the 1 mb/s i get :p Fell free to rehost it =)

I'll se if i can find somewhere else to host it too.

Kerion

09-01-2008 16:26:47

Well, for whatever reason, it just snapshotted forward, so all is well. My pings to your server are stellar (less then 150ms, which is good cross-atlantic), but I think your server itself may be have been stuttering a bit. It was creeping along, then all the sudden it just shot up to 1 m/s and was fine. So, just for your reference, something may be going wonky with your server :) If it's fine now, I don't see any need to re-host it.

dodongoxp

09-01-2008 16:40:40

very nice... i will try this out 8)

Marioko

09-01-2008 18:32:34

congratulation great work!! :D

Simple question: ¿Was hard make this bridge??

lilljohan

09-01-2008 18:48:26

No it was quite painless actually, took about 3 - 4 hours. I did only have some small problems with converting types from CLR to native, but it was nothing that google could not handle ;)

smernesto

09-01-2008 19:04:09

We need a repository to upload this kind of projects. All plugins and addons for mogre in the same place. Maybe later create the original SDK, and an optional Addons SDK also. Is a good new year for Mogre!!!. If we work as a team we can do many things.

Well I want also to learn more about C++/CLI for making wrappers, can you explain a little your steps for creating it please?.

I want to use the OgreMax loader but I don´t want to port it to C#, maybe is there any way to use C++/CLI for use it.

Marioko

09-01-2008 19:10:59

i tested MET and work nicely :D And just to say MOGRE and .NET has enough power to use all the nice things created initialy for OGRE ;D

About smernesto idea, i agree, later we will make a new folder in MOGRE SVN only for Addons. A nice thing that we can do also, is build the OGRE addons as static lib, and then just link the wrapper to the .lib In this way we only need one .DLL for the wrapper. Is just a elegant stuff :D

Beauty

11-01-2008 13:04:52

The project sounds good and also the idea of SNV for Mogre projects is fine (-:

I created an article in wiki.
Be free to include more information :wink:
http://www.ogre3d.org/wiki/index.php/MO ... in_Manager

Kerion

11-01-2008 18:02:18

I have a patch for MET, how should I submit it? :)

Basically, you were keeping your reference to the TerrainInfo passed in to CreateTerrain, and returning that as the GetTerrainInfo property, but that wasn't returning the info that is actually being referenced by the TerrainManager (in native code).

Instead, your TerrainInfo wrapper needs to be able to aggregate the ET:TerrainInfo* passed back from TerrainManager::getTerrainInfo() after createTerrain is called. I have patched both TerrainInfo and TerrainManager with the fix.

Without it, deformation doesn't work correctly because you are using your reference to TerrainInfo to do things like GetHeightAt, and PosToVertexX/Z, but your TerrainInfo doesn't have the reference to the actual ET:TerrainInfo that is being updated.

e: Also, I renamed GetTerrainInfo to TerrainInfo. Requires the prefixing of the type with MET:: (in the CLI/C++ code only of course), but that's no big deal and it keeps the property name consistent.

lilljohan

11-01-2008 18:20:06

Great =)

I was just trying to fix it my self, but since i was tired, it ended up with me yelling at Visual Studio and shutting it down.

I'll send you a PM with my email address so that you can mail the patch to me.

lilljohan

11-01-2008 18:58:07

Patch applied, zip file updated and it all seems to work as it should =)


Kerion: Almost exactly same code as the one i was writing, except i forgot to cast the reference, guess my cpp is getting a bit rusty ;)

Kerion

11-01-2008 19:12:09

MET in action:

Marioko

12-01-2008 00:08:14

OMG this is amazing, really great work... :D

We need more addons like this

if u want i can upload it to SVN repository :D

smernesto

12-01-2008 00:14:05

I downloaded the new fixed version and It doesn´t work for me, I compiled the testapp but when I run it I get a blue background, with the old MET I got a terrain. What happen? I am doing something wrong?

Ernesto

smernesto

12-01-2008 00:30:10

Marioko will you create a new wrappers folder in the SVN? something like Addons?

Also I think is a good thing to have in each addon folder a readme.txt with the status of the project (what is implemented, and what not), the person who create it, the original C++ version of the wrapped project and the license.

Something like:

Project Name: MyProject
Original Author: MyName
Forum Name : MyForumName
Original Project : Magic Scene Manager version 1.2
Original Project URL or Forum Topic: http://www.something.com
Current Status:
The project has implemented that, and that, and this.
The project can´t do this, and this, and this.

Well some information to the people who want some information and know the status of the project.

I don´t know what think the forum people?

Thanks

Ernesto

Marioko

12-01-2008 02:31:09

i am agree with u smernesto, is important keep original info about the addons and autors and license. Let me talk with GermanDZ to organize this. :D

Thanks for the idea

lilljohan

12-01-2008 08:56:02

It would be nice to have it up on the svn =)

Smernesto: I think the camera is off, try to rotate it by pressing down the mousewheel, it can be quite tricky to get to terrain ;)

pin

12-01-2008 10:56:10

Nice job lilljohan and everyone else!

Beauty

12-01-2008 13:50:36

Yes, it would be a very good thing to store / develop projects on a SVN where everybody can get it. Also the informations should be stored.

Beauty

12-01-2008 14:23:39

I added the screenshot of Kerion to the wiki article .
The subwindows for choosing texture is nice. Is it also included?

Kerion

12-01-2008 16:41:21

No, that's just an owner draw listbox. I take the splatting images, convert them to System.Drawing.Bitmap objects, then use those bitmaps as the items of the listbox. Then I use OwnerDrawVariable as the draw type, and in the MeasureItem event I set the returned Width and Height to that of the bitmap, then in the DrawItem event, I call the DrawBackground, then use the graphics object to draw the Bitmap item using the provided bounds, then I call the DrawSelectionBox.

The most difficult part was figuring out how to get a Mogre.Image in to a System.Drawing.Bitmap, but I ended up just brute forcing it (iterating over the entire Mogre.Image, getting a color value, and setting the corresponding color value in the System.Drawing.Bitmap. There is probably a more elegant way, but it worked).

Kerion

12-01-2008 17:29:19

I just tossed another quick patch to lilljohan.

This one adds default indexers to Brush and TerrainInfo, so you can do:


brush[x, y] = 0.1f;


In C# to mimic the following C++ code:


float& f = brush->at(x, y);
f = 0.1f;


Both TerrainInfo and Brush expose this functionality, as they are both mutable via at(x, y).

smernesto

12-01-2008 19:13:15

Thanks lilljohan now I rotated the camera and it works!.

smernesto

12-01-2008 20:01:05

Beauty I updated the wiki article, it needs some more information maybe lilljohan can add it.

lilljohan

12-01-2008 21:59:49

I have uploaded Kerions patch and once again i'm learning new stuff about C++/CLR =)

smernesto: I probably could throw together some sample code and information on the wiki, but i got an exam on Tuesday so i won't promise anything ;)

pin

15-01-2008 07:58:57

Why isn't ETM Wrapper in the wiki?
At least you can mention it in the add-ons list and link to this thread

[EDIT]

Ok I can't get the testapp working. I have removed MET from the project (because I have compilation issues with that) and I have added MET.dll to references.
When I try to run TestApp I'm getting a FileNotFound exception.

lizar

15-01-2008 08:56:17

First of all I wanna say that you have done a good job. So congratulations!!! And second, looking at what you have done, I wonder how you did to integrate the mogre render window into a windows form aplication. I have problems with this subject and I think that it must not be very difficult.
Could you help me!!

pin

15-01-2008 09:08:00

First of all I wanna say that you have done a good job. So congratulations!!! And second, looking at what you have done, I wonder how you did to integrate the mogre render window into a windows form aplication. I have problems with this subject and I think that it must not be very difficult.
Could you help me!!


Lizar there's a tutorial here addressing the issue. Try that and if it doesn't work make a separate thread for your question so that this thread doesn't get derailed. Cheers

lizar

15-01-2008 09:14:17

First of all I wanna say that you have done a good job. So congratulations!!! And second, looking at what you have done, I wonder how you did to integrate the mogre render window into a windows form aplication. I have problems with this subject and I think that it must not be very difficult.
Could you help me!!


Lizar there's a tutorial here addressing the issue. Try that and if it doesn't work make a separate thread for your question so that this thread doesn't get derailed. Cheers


Thanks I'll try to do it that way.

lilljohan

15-01-2008 09:48:13

Why isn't ETM Wrapper in the wiki?
At least you can mention it in the add-ons list and link to this thread

[EDIT]

Ok I can't get the testapp working. I have removed MET from the project (because I have compilation issues with that) and I have added MET.dll to references.
When I try to run TestApp I'm getting a FileNotFound exception.


Does it say which file? And does the .log file say anything suspicious?

pin

15-01-2008 10:22:23

12:20:34: Finished parsing scripts for resource group Internal
12:20:35: OGRE EXCEPTION(6:FileNotFoundException): Cannot locate resource brush.png in resource group ET or any other group. in ResourceGroupManager::openResource at ..\src\OgreResourceGroupManager.cpp (line 604)
12:20:37: *-*-* OGRE Shutdown
12:20:37: Unregistering ResourceManager for type Compositor
12:20:37: Unregistering ResourceManager for type Font


I did copy the the EL folder with everything inside it in Media/
I have no idea why I'm getting that error

You should have made the app self contained so that we don't have to copy anything i.e put everything needed in MET\testApp\bin\Release (except the native Ogre dlls) so that when you press the F5 button the app would start without you doing anything before that

lilljohan

15-01-2008 10:57:21

12:20:34: Finished parsing scripts for resource group Internal
12:20:35: OGRE EXCEPTION(6:FileNotFoundException): Cannot locate resource brush.png in resource group ET or any other group. in ResourceGroupManager::openResource at ..\src\OgreResourceGroupManager.cpp (line 604)
12:20:37: *-*-* OGRE Shutdown
12:20:37: Unregistering ResourceManager for type Compositor
12:20:37: Unregistering ResourceManager for type Font


I did copy the the EL folder with everything inside it in Media/
I have no idea why I'm getting that error

You should have made the app self contained so that we don't have to copy anything i.e put everything needed in MET\testApp\bin\Release (except the native Ogre dlls) so that when you press the F5 button the app would start without you doing anything before that


That's weird, all the resources are included in testapp\bin\media so that should not be any problem. Just pressing F5 to start works fine with me, event tried to download the release and to it from that one, and it worked fine ...

pin

15-01-2008 11:02:18

Ok I got it to run, the paths were screwed up.
I'm getting a blue screen though. Do I need special hardware for this?
I have a GF 5500 shader model 2.0

pin

15-01-2008 11:08:42

Ok I've got it to work, I've read about camera.
Ugh I've waisted almost half of the day trying to get this working.

P.S. lilljohan I still didn't figure it out, is this something you did or it's a wrapper for an existing Ogre add-on?

P.P.S Ok it's an Ogre addon made by CABAListic http://www.ogre3d.org/phpBB2/viewtopic.php?t=30955
(I was confused because you said you've spend some time on this and I thought you made it)

smernesto

15-01-2008 17:18:53

For use a Form for render, you can take a look to the MogreForm sample in the MogreSamples folder of the SDK.


@Beaty are you creating links to your articles? there is a MET article but where is referenced?

Beauty

15-01-2008 20:51:22

@Beaty are you creating links to your articles? there is a MET article but where is referenced?
Look here: www.ogre3d.org/wiki/index.php/ETM#Using_by_Mogre
And I added to category MOGRE.

I added links to several wiki pages. Look to [url=http://www.ogre3d.org/wiki/index.php?title=Special:Recentchanges&limit=250&days=30]http://www.ogre3d.org/wiki/index.php?title=Special:Recentchanges&limit=250&days=30 :wink:

By the way: Beauty with U please :evil:

pin

16-01-2008 07:29:00

Did someone managed to port the code to show the terrain lightmap?

I found this code snippet in C++

void updateLightmap()
{
Image lightmap;
ET::createTerrainLightmap(*mTerrainInfo, lightmap, 128, 128, Vector3(1, -1, 1), ColourValue(1,1,1),
ColourValue(0.3, 0.3, 0.3));

// get our dynamic texture and update its contents
TexturePtr tex = TextureManager::getSingleton().getByName("ETLightmap");
tex->getBuffer(0, 0)->blitFromMemory(lightmap.getPixelBox(0, 0));
}


[EDIT]

I came up with this code but I'm getting an error at the last line where I need to blit from memory
static void updateLightMap()
{
Mogre.Image lightmap = new Mogre.Image();
MET.TerrainInfo.CreateTerraingLightmap(terrainInfo,
lightmap,
128,
128,
new Mogre.Vector3(1, -1, 1),
new Mogre.ColourValue(1, 1, 1),
new Mogre.ColourValue(1, 1, 1));
Mogre.TexturePtr tex = Mogre.TextureManager.Singleton.GetByName("ETLightmap");
tex.GetBuffer(0, 0).BlitFromMemory(lightmap.GetPixelBox(0, 0));
}

Beauty

16-01-2008 08:42:49

A question to the wiki:
Shall I add a link from the [i]MOGRE[/i] frontpage to the [i]MOGRE Editable Terrain Manager[/i] article?
Or from [i]Tools and Libraries for Mogre[/i]? Or both?
See also my generally question on talk of the Mogre frontpage.

pin

16-01-2008 19:34:11

Sorry for bugging on this but has anyone got the lightmap working?

Kerion

17-01-2008 19:21:58

Yes, lightmaps work fine for me.

I am not at my home PC, so I can't copy and paste the code, but I'll try and get it to you later. To be honest, you're code looks fine. What kind of error is BlitFromMemory giving you?

e: Ah, I bet I know what the problem is, because this bit me. I bet you aren't creating the ETLightmap texture before you try and do GetByName, such that the resulting TexturePtr is null.

If you look in the ETsample.cpp, there is code in there to create the ETLightmap texture using TextureManager::createManual (I think that's the call). Look around for that, and move that in to your C# code before you attempt to call TextureManager.Singleton.GetByName(...).

pin

18-01-2008 06:32:19

Yes, lightmaps work fine for me.
e: Ah, I bet I know what the problem is, because this bit me. I bet you aren't creating the ETLightmap texture before you try and do GetByName, such that the resulting TexturePtr is null.

If you look in the ETsample.cpp, there is code in there to create the ETLightmap texture using TextureManager::createManual (I think that's the call). Look around for that, and move that in to your C# code before you attempt to call TextureManager.Singleton.GetByName(...).


Yeah, I spotted that eventually after going through the C++ sample a few times. I have my code now running without an error however the problem now is that I don't see a change in the scene. If I got it right the lighmap is when you have shadows drawn at the back of the hills. That doesn't happen in my scene

Here's the code I'm using:

program.cs:
/*
Copyright (c) 2007 Johan Gustafsson

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.
*/

using System;
using System.Collections.Generic;
using System.Text;
using MET;
using Mogre;

namespace testApp {
class Program {
static Mogre.Camera camera;
static Mogre.SceneManager sceneManager;
static Mogre.RenderWindow window;
static bool running = false;

static MET.TerrainManager terrainManager;
static MET.TerrainInfo terrainInfo;
static MET.SplattingManager splattingManager;
static MET.Brush brush;

static bool middleMouseDown = false;

static int oX = 0, oY = 0;
static bool resetMousePos = false;

static bool deform = true;

static Mogre.RaySceneQuery raySceneQuery;
static Mogre.Vector3 mousePos = new Mogre.Vector3(0, 0, 0);

static uint chosenTexture = 0;

static bool leftMouseDown = false;
static bool rightMouseDown = false;

static void Main(string[] args) {
testApp app = new testApp();

app.ClientSize = new System.Drawing.Size(800, 600);
app.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;

Mogre.Root root = new Mogre.Root("", "", "testApp.log");

root.LoadPlugin("RenderSystem_Direct3D9");
root.LoadPlugin("Plugin_OctreeSceneManager");
root.LoadPlugin("Plugin_CgProgramManager");

Mogre.RenderSystem renderSystem = root.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
root.RenderSystem = renderSystem;

root.Initialise(false);

Mogre.NameValuePairList misc = new Mogre.NameValuePairList();
misc["externalWindowHandle"] = app.Handle.ToString();
window = root.CreateRenderWindow("renderWindow", (uint)app.ClientSize.Width, (uint)app.ClientSize.Height, false, misc);

//mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

sceneManager = root.CreateSceneManager("OctreeSceneManager");
sceneManager.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f);

camera = sceneManager.CreateCamera("the_camera");
camera.SetPosition(200, 500, 200);
camera.NearClipDistance = 0.1f;
camera.FarClipDistance = 6000.0f;

Mogre.Viewport viewport = window.AddViewport(camera);
viewport.BackgroundColour = new Mogre.ColourValue(0.5f, 0.5f, 0.9f, 1.0f);

camera.AspectRatio = (float)window.Width / (float)window.Height;

Mogre.ResourceGroupManager.Singleton.AddResourceLocation("media", "FileSystem", "ET");
Mogre.ResourceGroupManager.Singleton.AddResourceLocation("media\\ET", "FileSystem", "ET");
Mogre.ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

terrainManager = new MET.TerrainManager(sceneManager);
terrainManager.SetLodErrorMargin(2, (uint)viewport.ActualHeight);
terrainManager.SetUseLodMorphing(true, 0.2f, "morphFactor");

float[] hm = new float[513 * 513];
for(int i = 0; i < 513 * 513; i++)
hm[i] = 0.5f;
terrainInfo = new MET.TerrainInfo(513, 513, hm);
terrainInfo.Extents = new Mogre.AxisAlignedBox(0, 0, 0, 2000, 512, 2000);
terrainManager.CreateTerrain(terrainInfo);
terrainInfo.Dispose();
terrainInfo = terrainManager.TerrainInfo;

splattingManager = new MET.SplattingManager("ETSplatting", "ET", 128, 128, 3);
splattingManager.NumTextures = 6;


//// create a manual lightmap texture
Mogre.TexturePtr lightmapTex = Mogre.TextureManager.Singleton.CreateManual(
"ETLightmap",
"ET",
Mogre.TextureType.TEX_TYPE_2D,
128,
128,
1,
Mogre.PixelFormat.PF_BYTE_RGB);
Mogre.Image lightmap = new Mogre.Image();

MET.TerrainInfo.CreateTerraingLightmap(terrainInfo,
lightmap,
128,
128,
new Mogre.Vector3(1, -1, 1),
new Mogre.ColourValue(1, 1, 1),
new Mogre.ColourValue(0.3f, 0.3f, 0.3f));

lightmapTex.GetBuffer(0, 0).BlitFromMemory(lightmap.GetPixelBox(0, 0));

Mogre.MaterialPtr material = Mogre.MaterialManager.Singleton.GetByName("ETTerrainMaterial");
terrainManager.Material = material;

Mogre.Image image = new Mogre.Image();
image.Load("brush.png", "ET");
image.Resize(16, 16);
brush = MET.Brush.LoadBrushFromImage(image);

raySceneQuery = sceneManager.CreateRayQuery(new Mogre.Ray());

app.MouseDown += OnMouseDown;
app.MouseUp += OnMouseUp;
app.MouseMove += OnMouseMove;
app.KeyUp += OnKeyUp;
app.KeyDown += OnKeyDown;

running = true;

app.Show();

Timer.Start();

while(running) {
float delta = Timer.Delta();
if (rightMouseDown || leftMouseDown) {
if (deform) {
float intens = delta * 0.2f * ((leftMouseDown) ? 1.0f : -1.0f);

int x = terrainInfo.PosToVertexX(mousePos.x);
int z = terrainInfo.PosToVertexZ(mousePos.z);
terrainManager.Deform(x, z, brush, intens);
} else {
float intens = delta * 3 * ((leftMouseDown) ? 1.0f : -1.0f);

int x = terrainInfo.PosToVertexX(mousePos.x);
int z = terrainInfo.PosToVertexZ(mousePos.z);

splattingManager.Paint(chosenTexture, x, z, brush, intens);
}
}

root.RenderOneFrame();
System.Windows.Forms.Application.DoEvents();
running = running && !app.IsDisposed;
}

splattingManager.Dispose();
brush.Dispose();
terrainInfo.Dispose();
terrainManager.Dispose();

material.Dispose();

root.Dispose();
root = null;
}


static void updateLightMap()
{
Mogre.Image lightmap = new Mogre.Image();
Mogre.TexturePtr tex;
MET.TerrainInfo.CreateTerraingLightmap(terrainInfo,
lightmap,
128,
128,
new Mogre.Vector3(1, -1, 1),
new Mogre.ColourValue(1, 1, 1),
new Mogre.ColourValue(0.3f, 0.3f, 0.3f));
tex = Mogre.TextureManager.Singleton.GetByName("ETLightmap");
//tex = Mogre.TextureManager.Singleton.Load("ETlightmap.png", Mogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
tex.GetBuffer(0, 0).BlitFromMemory(lightmap.GetPixelBox(0, 0));
}

static void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
if (e.Button == System.Windows.Forms.MouseButtons.Middle)
middleMouseDown = true;

if (e.Button == System.Windows.Forms.MouseButtons.Left)
leftMouseDown = true;
if (e.Button == System.Windows.Forms.MouseButtons.Right)
rightMouseDown = true;
}

static void OnMouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
if (e.Button == System.Windows.Forms.MouseButtons.Middle) {
middleMouseDown = false;
resetMousePos = true;
}

if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
leftMouseDown = false;
updateLightMap();
}
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
rightMouseDown = false;
updateLightMap();
}
}

static void OnMouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
int dx = (resetMousePos) ? 0 : oX - e.X;
int dy = (resetMousePos) ? 0 : oY - e.Y;

oX = e.X;
oY = e.Y;

if (middleMouseDown) {
camera.Yaw(dx * 0.1f);
camera.Pitch(dy * 0.1f);

resetMousePos = false;
}

uint w, h, cd;
int l, r;

window.GetMetrics(out w, out h, out cd, out l, out r);

Mogre.Ray ray = camera.GetCameraToViewportRay((float)e.X / (float)w, (float)e.Y / (float)h);
Mogre.Vector3 result = terrainInfo.RayIntersects(ray);
if(result != null) {
mousePos.x = result.x;
mousePos.y = result.y;
mousePos.z = result.z;
}
}

static void OnKeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
if (middleMouseDown) {
if (e.KeyCode == System.Windows.Forms.Keys.W)
camera.MoveRelative(new Mogre.Vector3(0, 0, -9));
if (e.KeyCode == System.Windows.Forms.Keys.S)
camera.MoveRelative(new Mogre.Vector3(0, 0, 9));
if (e.KeyCode == System.Windows.Forms.Keys.A)
camera.MoveRelative(new Mogre.Vector3(-9, 0, 0));
if (e.KeyCode == System.Windows.Forms.Keys.D)
camera.MoveRelative(new Mogre.Vector3(9, 0, 0));
}
}

static void OnKeyUp(object sender, System.Windows.Forms.KeyEventArgs e) {
if (e.KeyCode == System.Windows.Forms.Keys.F5)
deform = !deform;

if (e.KeyCode == System.Windows.Forms.Keys.D1)
chosenTexture = 0;
if (e.KeyCode == System.Windows.Forms.Keys.D2)
chosenTexture = 1;
if (e.KeyCode == System.Windows.Forms.Keys.D3)
chosenTexture = 2;
if (e.KeyCode == System.Windows.Forms.Keys.D4)
chosenTexture = 3;
if (e.KeyCode == System.Windows.Forms.Keys.D5)
chosenTexture = 4;
if (e.KeyCode == System.Windows.Forms.Keys.D6)
chosenTexture = 5;
if (e.KeyCode == System.Windows.Forms.Keys.Escape)
running = false;

if (e.KeyCode == System.Windows.Forms.Keys.F10) {
Mogre.Image img = new Mogre.Image();
MET.TerrainInfo.SaveHeightmapToImage(terrainInfo, img);
img.Save("heightmap.png");

splattingManager.SaveMapToImage(0, img);
img.Save("splat1.png");

splattingManager.SaveMapToImage(1, img);
img.Save("splat2.png");
}
}
}
}


testApp.cs :

/*
Copyright (c) 2007 Johan Gustafsson

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace testApp {
public partial class testApp : Form {
public testApp() {
InitializeComponent();
}

snorr

10-03-2008 17:26:03

Hmm, pin, ever got the lightmap in the sample to work? I'm using the same sample code and cannot see any lightmaps, it's just one static ambient color in the whole terrain (even though I haven't set one).

snorr

11-03-2008 09:42:04

Ah nvm, the lightmap pass was missing in the ETTerrain.material file =)

raygeee

14-03-2008 15:54:05

I've got a problem with preloading the resources ET needs:

If I call
ResourceGroupManager.Singleton.LoadResourceGroup("ET")
everything seems to be running ok. The resources are being loaded.
But if I look into my logfile it says it couldn't find ETSplatting0 and ETSplatting1. So I now looked into the material file and found out that those two files are supposed to be managed dynamically which is fine for me.

If I then initialize my first scene with this code
' Create MET-SplattingManager
_SplattingMgr = New MET.SplattingManager("ETSplatting", "ET", 512, 512, 3)
' Specify number of splatting textures we need to handle.
_SplattingMgr.NumTextures = 6 <-- Exception is thrown here

I get an error stating that the resource ETSplatting0 already exists and can't be created. Seems like ET tries to create them when it sets the number of splatting textures. Unfortunately changing the baseName (first parameter in the constructor) leads to no errors but also no terrain. Therefore the name is needed.

I understand the problem but I don't know how to solve it. How can I preload all the ET resources without loading those 2 dynamically created resources?

If it's not a problem with MET but rather ETM itself I'll ask them in their forum.

PS: Don't be confused with the syntax, it's VB.NET ;-)

raygeee

14-03-2008 19:41:12

Seems like I have to change my preloading order... (http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=6743)

lilljohan

26-07-2008 07:29:28

New version available, just recompiled it against Mogre 1.4.8 =)

arakon

26-07-2008 19:23:50

Thanks a bunch! I'm still having some kind of problem though. I used the Testapp in the zip, and I set it to use the precompiled MET.DLL (SO I didn't need to setup the rest of it), and the MOGRE.DLL from the latest download. Testapp compiled OK, but when I run it (after copying the other support DLLs in), I get :

Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
at ET.TerrainManager.createTerrain(TerrainManager* , TerrainInfo* , UInt32 ,
UInt32 , Boolean )
at MET.TerrainManager.CreateTerrain(TerrainInfo info)
at testApp.Program.Main(String[] args)


The other mogre examples run OK.
Any thoughts? I seem to be doing something wrong.
Thanks

lilljohan

26-07-2008 19:42:38

Thanks a bunch! I'm still having some kind of problem though. I used the Testapp in the zip, and I set it to use the precompiled MET.DLL (SO I didn't need to setup the rest of it), and the MOGRE.DLL from the latest download. Testapp compiled OK, but when I run it (after copying the other support DLLs in), I get :

Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
at ET.TerrainManager.createTerrain(TerrainManager* , TerrainInfo* , UInt32 ,
UInt32 , Boolean )
at MET.TerrainManager.CreateTerrain(TerrainInfo info)
at testApp.Program.Main(String[] args)


The other mogre examples run OK.
Any thoughts? I seem to be doing something wrong.
Thanks

Anything useful in ogre.log?
Did you reference debug or release?

arakon

26-07-2008 22:34:04

For some reason I cannot seem to get it to run in debug mode at all. It complaints about an assembly type mismatch of some sort.

The log does not contain any useful information either.
I attempted to add it to one of the Mogre demo's, just to see if it was a simple problem. I can add the TerrainManager, but not a terrain info.

lilljohan

27-07-2008 17:41:55

For some reason I cannot seem to get it to run in debug mode at all. It complaints about an assembly type mismatch of some sort.

The log does not contain any useful information either.
I attempted to add it to one of the Mogre demo's, just to see if it was a simple problem. I can add the TerrainManager, but not a terrain info.

It sounds like you are linking against Mogre release version in debug. But it should still work just fine in release mode ... this is strange ...

Beauty

29-07-2008 10:43:42

New version available, just recompiled it against Mogre 1.4.8 =)Is it the same download link?
www.tinyrocket.se/MET.zip

If there are important changes, please update the Wiki.
http://www.ogre3d.org/wiki/index.php/MO ... in_Manager

lilljohan

29-07-2008 10:51:11

New version available, just recompiled it against Mogre 1.4.8 =)Is it the same download link?
www.tinyrocket.se/MET.zip

If there are important changes, please update the Wiki.
http://www.ogre3d.org/wiki/index.php/MO ... in_Manager

Same download link, no changes except i referenced Mogre 1.4.8 instead.

telchar

03-08-2008 21:09:30

I get an error when doing :

terrainManager.createTerrain(terrainInfo);


Here is the stack trace:
à ET.TerrainManager.createTerrain(TerrainManager* , TerrainInfo* , UInt32 , UInt32 , Boolean )
à MET.TerrainManager.CreateTerrain(TerrainInfo info)
à LDA.MapEditor.Map..ctor(SceneManager sceneMgr, Viewport viewport, String mapName) dans E:\lda\MapEditor\Map.cs:ligne 23


I'm using VStudio 2008 and i have installed the last version of MOGRE and MET. and i'm using windows vista. If that helps...

I don't understand what i'm missing...

lilljohan

04-08-2008 09:47:38

I get an error when doing :

terrainManager.createTerrain(terrainInfo);


Here is the stack trace:
à ET.TerrainManager.createTerrain(TerrainManager* , TerrainInfo* , UInt32 , UInt32 , Boolean )
à MET.TerrainManager.CreateTerrain(TerrainInfo info)
à LDA.MapEditor.Map..ctor(SceneManager sceneMgr, Viewport viewport, String mapName) dans E:\lda\MapEditor\Map.cs:ligne 23


I'm using VStudio 2008 and i have installed the last version of MOGRE and MET. and i'm using windows vista. If that helps...

I don't understand what i'm missing...

Yeeah, i'm getting the same error :) But i don't have a clue on why it doesn't work =/ but i will look into it.

arakon

07-08-2008 14:27:03

I managed to get mine to work again, but I had to recompile ETM, and then also MET. It seems to work now.

lilljohan

07-08-2008 15:07:31

I managed to get mine to work again, but I had to recompile ETM, and then also MET. It seems to work now.
Weird, done that a dozen times ... Guess i will just have to try it again =)

side

18-08-2008 06:32:53

I managed to get mine to work again, but I had to recompile ETM, and then also MET. It seems to work now.
Is there a chance that you could upload the working dll's somewhere? Would help me (and apparently many others) a great deal :)

lilljohan

20-08-2008 20:18:02

I will probably try to recompile sometime soon, and if it works then i will upload it again .. but i got a re-exam next week and a lot of work, so it will probably have to wait.

Chulein

19-09-2008 13:04:40

Hello.

Could someone please be so kind and explain to me how to get the example in Managed Editable Terrain to work.

So far ive managed to start the example, but the the appwindow has only a light blue background. I read earlier in this thread that this was the camera that just pointed in the wrong direction, and was fixed by changing the direction camera with the middlebutton pressed down on the mouse..
In my case the program crashes on the "root.RenderOneFrame();" when i press the middlemouse.

second.. do i need the mogre version 1.4.8 to use MET? Im using 1.4.6 right now..
When i loaded the 1.4.8 i got an error.

"A procedure imported by 'Mogre, Version=1.4.8.0, Culture=neutral, PublicKeyToken=null' could not be loaded"
even though i re-referenced the mogre.dll in the project. both debug and release.

Im using VS Express 2005.

and the MET version i got from:
http://www.ogre3d.org/wiki/index.php/MO ... in_Manager


if somebody could take some time and help me with this i would be most grateful.

Bostich

19-09-2008 13:17:09


When i loaded the 1.4.8 i got an error loading.

"A procedure imported by 'Mogre, Version=1.4.8.0, Culture=neutral, PublicKeyToken=null' could not be loaded"
even though i re-referenced the mogre.dll in the project. both debug and release.


Hello Chulein,

i got _exactly_ the same Error message when using Mogre 1.4.8.. Looking also for any help :)

Chulein

19-09-2008 14:23:15

Hi Bostich.

did you try running it with 1.4.6?

Bostich

19-09-2008 14:26:14

Hello Chulein,

yes i did, and it didnt work :/. Dont remember the exact error message (currently iam at work 8) )

lilljohan

10-10-2008 12:23:13

I spent an hour today fixing MET, I cleaned up the directories, modified the solution file a bit, fixed x86 compilation target etc. Both debug / release versions compile / run.

I have uploaded the new version.
http://www.tinyrocket.se/MET.zip

Chulein

13-10-2008 09:37:32

Thank you so much lilljohan!

It now works great! but I still had some problems running it.
I got a error message opening the sample project.

it works now after i changed the line:

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
to
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
in
MET\Sample\Sample.sln


Works great with 1.4.8 and 1.4.9
Tested with 1.4.6 but I get a crash when trying to move camera.


Also.. Framework 3.5 needs to be installed.
Im using VS2005


Thanks again!

lilljohan

13-10-2008 13:19:08

You would probably need to recompile ETM to get it to work with 1.4.6

I compiled it against .NET 3.5 since it's the default setting in vs2008, but i could probably change it.

LaGhoule

06-11-2008 21:48:47

Hi,
i just download the Mogre Editable Terrain and i can't open the <sample> project. (MET.zip)

I got the following error message :

Unable to read project file 'Sample.csproj'. C:\Documents and Settings\blalonde\Desktop\MET\Sample\Sample.csproj(109,11): The imported project "C:\Microsoft.CSharp.targets> was not found. Confim the path in the <Import> declaration is correct, and thaht the files exists on disk.

Then the VS close. I use MVS 2005 Version 8.0.5

Anyone got this probleme??

Tx for your help!

Chulein

07-11-2008 07:24:11

Hi LaGhoule

Find the Sample.sln file and change the code from



<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

to

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />




Chulein

LaGhoule

07-11-2008 14:37:30

The MET.zip doesnt contain <Sample.sln>.

satik

07-04-2009 10:32:16

Hi all, I have a problem, I used the pin's code and I dont have any textures on terrain:



I copied textures etc. to debug/ET, in code I set path for it and it doesnt say anything about missing textures, any ideas? :(

EDIT: or Maybe liljohan could upload the Sample working in VS2005 (the one from example doesnt contain *.sln file for opening in visual studio)

noobs

15-11-2009 13:38:00

hmm just compiled it against mogre 1.6.4(i Think) and when i try to run the sample get this error in the log
15:35:05: Added resource location '../../media' of type 'FileSystem' to resource group 'ET'
15:35:05: Added resource location '../../media/ET' of type 'FileSystem' to resource group 'ET'
15:35:05: Parsing scripts for resource group Autodetect
15:35:05: Finished parsing scripts for resource group Autodetect
15:35:05: Parsing scripts for resource group ET
15:35:05: Parsing script ETShader.program
15:35:05: Parsing script ETTerrain.material
15:35:05: Finished parsing scripts for resource group ET
15:35:05: Parsing scripts for resource group General
15:35:05: Finished parsing scripts for resource group General
15:35:05: Parsing scripts for resource group Internal
15:35:05: Finished parsing scripts for resource group Internal
15:38:50: OGRE EXCEPTION(5:ItemIdentityException): SceneNode 'ETTerrain/Terrain' not found. in SceneManager::getSceneNode at ..\src\OgreSceneManager.cpp (line 830)


And

void CreateTerrain(MET::TerrainInfo^ info, unsigned int tileSize, int maxLOD, bool vertexNormals) {
// 1/11/08: Kerion @ Ogre3D: We now take the getTerrainInfo() reference in aggregate instead
// of keeping our own reference. MET::TerrainInfo is now aware of whether it owns, or does not
// own, the reference to the ET::TerrainInfo.
----> terrainManager->createTerrain(*info->_getNativePtr(), tileSize, maxLOD, vertexNormals);
terrainInfo = gcnew MET::TerrainInfo((ET::TerrainInfo*)(&terrainManager->getTerrainInfo()));
}


Thats the point where it crashes.

Has probably some thing to do whit me using mogre 1.6.4?

CoMPMStR

22-12-2009 23:14:50

When I try to use the current version in my project, I get an error "A procedure imported by 'MET, Version=1.0.3205.21959, Culture=neutral, PublicKeyToken=null' could not be loaded." Both ETM and MET dlls are in the same folder so I can only see one problem. The same error occurs when I try to run the sample project.

I would like to know if anyone is going to update this for Mogre v1.6.4?

Kohedlo

01-01-2010 01:12:59

Hi all! Our Studio cook dll of METM for Mogre1.6.4.But only Release DLL.

Let all have nice coding with this nice manager! :wink:

http://kohedlostudio.narod.ru/METMForMogre1.6.4.rar

an error "A procedure imported by 'MET, Version=1.0.3205.21959, Culture=neutral, PublicKeyToken=null' could not be loaded." - is fixed)

u2ro

24-02-2011 23:39:33

Hello,

Is there any info about support of the newest Mogre SDK?

Thanks,
u2ro

Beauty

25-02-2011 01:13:15

Hi u2ro,
welcome to Mogre :D

I suppose this project doesn't work with the current version of Mogre.
The last posts about the managed ETM are very old.
Generally it would be possible to update the project to work with the current Mogre version, but I suppose this needs much work and deep project knowledge.

I don't know about the current state of the Ogre version.
At a quick look this also seems to be outdatet.

Well, look yourself more deeply here:
http://www.ogre3d.org/tikiwiki/ETM
http://www.oddbeat.de/wiki/etm
viewforum.php?f=16 (ETM forum section)