Jump to content
The Dark Mod Forums

Recommended Posts

Posted

I'm working on a small program that can make random terrain, like this:

http://i91.photobucket.com/albums/k289/Jes...15-02-23-40.jpg

http://i91.photobucket.com/albums/k289/Jes...15-03-02-05.jpg

http://i91.photobucket.com/albums/k289/Jes...15-02-16-12.jpg

 

To do so, I looked at some map files to see how patches are represented in the map/pfb files. This is an example of a prefab with one patch in it:

I've figured out what most of it means, but not the numbers in red.

Version 2

// entity 0

{

"classname" "worldspawn"

// primitive 0

{

patchDef2

{

"_default"

( 3 3 0 0 0 )

(

( ( 0 0 35 0 0 ) ( 0 32 34 0 0 ) ( 0 64 7 0 0 ) )

( ( 32 0 59 0 0 ) ( 32 32 0 0 0 ) ( 32 64 82 0 0 ) )

( ( 64 0 124 0 0 ) ( 64 32 21 0 0 ) ( 64 64 73 0 0 ) )

)

}

}

}

I've tried changing the numbers to other numbers, but it seems to do nothing (or I'm not looking hard enough).

Any help would be... helpful. :rolleyes:

 

Jesps

Posted
I've tried changing the numbers to other numbers, but it seems to do nothing (or I'm not looking hard enough).

Any help would be... helpful. :rolleyes:

The patch format is like this, in a schematic view:

<Header>
{
 <shader>
 <parameters>
 <patchMatrix>
}

 

The things you are looking at is the structure, which is formatted like this:

// for a patchDef2
( patchWidth pathHeight 0 0 0 )	

// for a patchDef3 (fixed tesselation)
( patchWidth pathHeight patchSubdivisionX patchSubdivisionY 0 0 0 )

 

The patch matrix consists of all patch vertex elemeents, looped over columns and rows, so a 3x3 patch would have 9 elements. One element looks like this:

( x y z s t )

are the world coordinates of the patch, and are the texture coordinates of that patch.

 

Does this help?

 

What kind of language are you using for your tool? I'd like to see such a feature in DarkRadiant, so you might as well use the DarkRadiant Patch API to generate such terrain.

Posted
The things you are looking at is the <parameters> structure, which is formatted like this:

// for a patchDef2<BR>( patchWidth pathHeight 0 0 0 )   
// for a patchDef3 (fixed tesselation) 
( patchWidth pathHeight patchSubdivisionX patchSubdivisionY 0 0 0 )

<x,y,z> are the world coordinates of the patch, and <s,t> are the texture coordinates of that patch.

 

Does this help?

 

It sure does. But what about the 3 zeros in "( patchWidth pathHeight 0 0 0 )"?

 

What kind of language are you using for your tool? I'd like to see such a feature in DarkRadiant, so you might as well use the DarkRadiant Patch API to generate such terrain.

 

I'm using C# as it is the only programming language I have any experience in.

Posted
It sure does. But what about the 3 zeros in "( patchWidth pathHeight 0 0 0 )"?

The zeros do nothing, they are always 0 0 0. I guess they are remnants from Quake 3 or something, where surfaces could have "flags", like "detail" or "structural".

 

I'm using C# as it is the only programming language I have any experience in.

I guess one would be able to port your code to use DarkRadiant's C++ interface, which provides methods to create patches, change their dimension, assign coordinates, and project textures. It's not too hard once you have grasped the basics of the scenegraph, which I could assist you with. I could also provide you with some sort of "hollow" functions, which could be fleshed out by you. Don't know if you're interested in such a project.

 

Also, I'd be curious whether there is a defined C++/C# interface, like boost::python or something similar?

Posted
I guess one would be able to port your code to use DarkRadiant's C++ interface, which provides methods to create patches, change their dimension, assign coordinates, and project textures. It's not too hard once you have grasped the basics of the scenegraph, which I could assist you with. I could also provide you with some sort of "hollow" functions, which could be fleshed out by you. Don't know if you're interested in such a project.

 

From what I can see there are many similarities between C++ and C#. So yes I would be interested in something like that.

Posted

Well, let's have a go then. :)

 

You need a few things to compile the DarkRadiant sources, namely VC++ 2005 Express, the Platform SDK and the sources from SVN (you'll need TortoiseSVN or something like that to checkout the sources). There is a compilation guide on the wiki, which includes some instructions: http://wiki.thedarkmod.com/index.php/...mpilation_Guide

 

VC++ 2005 Express should be available here: http://msdn2.microsoft.com/de-de/express/a...401(en-us).aspx It's a large download, so beware if you're on limited bandwidth.

 

The Platform SDK is available from the MS website for free (last time I checked). I posted some installation instructions for the SDK somewhere in the internal forums, let me dig them out...

 

...here they are:

I'm using this Platform SDK, it's a 400 MB ISO and this works.

 

http://www.microsoft.com/downloads/details...;displaylang=en

 

You don't need to install everything from that package, I'll edit this post with the settings.

 

edit: You can deselect everything except:

- Configuration Options (not sure about the child option Register Environment Variables, select that too)

- Microsoft Windows Core SDK

- Microsoft Data Access Services (MDAC) SDK

- Debugging Tools for Windows

 

Once you have the Platform SDK installed, you'll need to

- Open VC++ 2005

- Go to menu Tools > Options

- Go to Projects and Solutions > VC++ Directories

- Select "Show Directories for" Include files

- Add the folder C:\Program Files\Microsoft Platform SDK\Include

- Select "Show Directories for" Library files

- Add the folder C:\Program Files\Microsoft Platform SDK\Lib

- Then close VC++, go to the folder C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults

- Open the file corewin_express.vsprops using a text editor and replace the XML key with this

<Tool Name="VCLinkerTool" AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib" />

 

Let me know if you need help, no point in chewing silently on problems.

  • 2 weeks later...
Posted

Ok, so I downloaded Visual C++ and the source.

 

I had an idea to make a method that travells though the array of vertices in the selected pathes, and move each of them, but I can't seem to find any method for cycling though vertices. Is there such one?

Posted
I had an idea to make a method that travells though the array of vertices in the selected pathes, and move each of them, but I can't seem to find any method for cycling though vertices. Is there such one?

There are two possibilities:

 

Either you take the iterator approach using the Patch::begin() and Patch::end() methods:

UndoableCommand cmd("myPatchOperation");
patch.undoSave();

for (PatchControlIter i = patch.begin(); i != patch.end(); i++) {
  PatchControl& control = *i;
  control.m_vertex = ... // do something with that vertex here
}

patch.controlPointsChanged();

 

Or you can cycle over specific matrix elements, using the getWidth() and getHeight() methods, like this:

UndoableCommand cmd("myPatchOperation");
patch.undoSave();

for (std::size_t w = 0; w < patch.getWidth(); w++) {
  for (std::size_t h = 0; h < patch.getHeight(); h++) {
  PatchControl& control = patch.ctrlAt(w, h);
  control.m_vertex = ... // do something with that vertex here
  }
}

patch.controlPointsChanged();

Posted

That worked wonders! :) Thanks greebo.

But: The vertex is surposed to move a random amount of units up. For that I'm using:

srand(time(0));<BR>randomNumber = (rand()%maxValue) + 1;

</FONT>

And I can't get rand() to generate a true random number. At best it creates a number close to the previous one.

Posted
And I can't get rand() to generate a true random number. At best it creates a number close to the previous one.

 

Use this (taken from the objectives editor plugin), you'll need to #include

int x = int(yourMaxValue * (float(std::rand()) / float(RAND_MAX)));

Posted (edited)

This seems to kinda work...

 

[size="2"]void BulgePatch() 
{[/size]

[size="2"] Patch& patch = selection::algorithm::getLastSelectedPatch();[/size]

[size="2"] UndoableCommand cmd("BulgePatch");
patch.undoSave();
int maxValue = 16;
for (PatchControlIter i = patch.begin(); i != patch.end(); i++) 
{
 PatchControl& control = *i;
 int randomNumber = int(maxValue * (float(std::rand()) / float(RAND_MAX)));
 control.m_vertex.set(control.m_vertex.x(), control.m_vertex.y(), control.m_vertex.z() + randomNumber);
}
patch.controlPointsChanged();
}[/size]

GlobalEventManager().addCommand("BulgePatch", FreeCaller<patch::BulgePatch>());

at least for a single, horisontal, flat patch.

I did not need to add cstdlib, but maybe that's because I've put it in the patchmanip.cpp.

Here is an example of what can be done with just one click:

http://i91.photobucket.com/albums/k289/Jes...20Mod/Patch.jpg

Edited by Jesps
Posted

Nice one, this looks quite useable!

 

Do you want me to commit this to SVN? If yes, I'll need a .diff or .patch file (you can create these in TortoiseSVN's context menu).

 

Btw: you can add commands to the menu or the toolbars very easily by editing the menu.xml or user.xml files.

Posted

Jesps, I just committed your patch for the Bulge Patch feature, nicely done. :)

 

I also checked in a few code changes, so that multiple selected patches can be affected by that operation too. Plus some minor changes with regard to the coding style guidelines.

 

I don't know what your further plans are, or how much time you have for coding, but in case you're interested in further collaboration, feel free to post here. We can always need a helping hand here and there, but I guess you know that. :)

Posted

Thanks greebo. Also thanks for helping me make the feature.

I would be lying if I claimed that I have plenty of time for coding, due to studies. So I won't commit myself to anything, but if I get other ideas like this one I'll be sure to post it! :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • JackFarmer

      "The Year of the Rat." 
      😄

      Al Stewart must be proud of you!
      Happy testing!
      @MirceaKitsune
      · 1 reply
    • datiswous

      I posted about it before, but I think the default tdm logo video looks outdated. For a (i.m.o.) better looking version, you can download the pk4 attached to this post and plonk it in your tdm root folder. Every mission that starts with the tdm logo then starts with the better looking one. Try for example mission COS1 Pearls and Swine.
      tdm_logo_video.pk4
      · 2 replies
    • JackFarmer

      Kill the bots! (see the "Who is online" bar)
      · 3 replies
    • STiFU

      I finished DOOM - The Dark Ages the other day. It is a decent shooter, but not as great as its predecessors, especially because of the soundtrack.
      · 5 replies
×
×
  • Create New...