PDA

View Full Version : UnrealScript: making custom brush builders


tarquin
26th Dec 2000, 05:57 PM
Does anyone know anything about making new brush builders in UE? Has anyone made custom builders yet?
Building levels has given me ideas for brush builders I'd like to make, and from what I've read here, brush builders would be well-received (something that makes cylinder sections for example -- no more intersecting or clipping to make a 1/4 cylinder).
I've come stuck on a few things, though.
I have the maths background, and can muddle my way through scripting, but have no idea how to make the code work in UE.

How do you make a new brush builder class show up on the UE tools, so you can test it / use it?
Having failed at that, I tried tinkering with the existing ones (carefully), and new variables entered into the script showed up in the right-click brush builder measurements box after a recompile, however defaults specified in the class properties box didn't show up -- the new variables has bizarre values (5524 I think).
Furthermore, other alterations to the code had no effect -- the brush was built as normal.

Any help & advice much appreciated!
(or ideas for builders -- if I do get this off the ground I'll be making them publicly available)

purice
26th Dec 2000, 07:19 PM
i'd like to see a torus.

are you using unrealed to compile your script?
if so, you might want to look into editing with .uc files and ucc.

there's often a lot of code in the source that doesn't show up in unrealed.

the nice people at chimeric have it all laid out for your perusal:

http://www.planetunreal.com/chimeric/tutorials/tut20.html


[Edited by purice on December 26th, 2000 at 07:25 PM]

tarquin
26th Dec 2000, 07:29 PM
This whole compiling lark might be beyond me... either that, or I need a kick in the right direction.
On the other hand, the vector stuff to make a torus wouldn't be too hard. neat idea.

purice
26th Dec 2000, 07:47 PM
at least export the scripts and take a look at them.
open the actor class browser then: file->export_all_scripts
let it do it's thing then look in the editor folder in your unreal tournament directory. open the classes folder and you'll find the .uc files for the brush builders.

purice
26th Dec 2000, 08:53 PM
i found an opengl glut function that draws a torus. at least i found the <italics>name</italics> of the function
i'll keep digging until i find the source..

Slick_Willy
27th Dec 2000, 10:47 AM
I agree this would be good but there are ways to do most brushes with the built in brush builders. For example, you can make a 1/4 cylinder by just going into the 2d editor and making a square and revolve it using only 1/4 of the 360 parts. Like 24 per 360 but only make 6, giving a 6 walled 1/4 cylinder. I use this a lot to make curved corner columns and pillars. I have a couple of pics at: http://www.planetunreal.com/slick/semisolids_nodes.htm

This technique is also good for making any kind decorational column, like a roman style pillar or a lamp, bed post, etc. Just draw half of the shape and revolve it the full 360.

tarquin
27th Dec 2000, 04:01 PM
I've been pottering around with the scripts in the UE script editor.
I've managed to make a torus builder, but only by rewriting one of the existing builders, as I don't know how to 'run' a new builder object.

Try this:
In the actor browser, find object>brushbuilder>conebuilder.
Open the script editor, and replace the whole code with the script at the end of this post. Recompile and try it!
BTW, the cone builder will be back to normal next time UEd is run.
[oops! I pasted the wrong version earlier. now fixed]

This works fine (any problems blame my copying + pasting skills)-- only one size for now, but the variables are in place. Different # of faces & an 'align to side' option for both circles are possible too. May also be able to name the polys for easy selection of 'slices'.
My problem is this: how do I make new brushbuilder objects that UE will recognise, and make them accessible in the toolbox?

code:

//=============================================================================
// ConeBuilder: doctored to build a torus brush.
//=============================================================================
class ConeBuilder
extends BrushBuilder;

var() float Height, CapHeight, OuterRadius, InnerRadius;
var() int Sides;
var() name GroupName;
var() bool AlignToSide, Hollow;

function RHVertex3f ( int vx , int vy , int vz )
{
Vertex3f( vx, -vy, vz );
}

function bool Build()
{
local int i, j, n, WheelSides, TubeSides, CentrumRadius, TubeRadius, TubeOfs;

Wheelsides = 8;
Tubesides = 8;
CentrumRadius = 256 ;
TubeRadius = 64 ;
TubeOfs = 0 ;

if( Sides<3 )
return BadParameters();
if( Height<=0 || OuterRadius<=0 )
return BadParameters();
if( Hollow && (InnerRadius<=0 || InnerRadius>=OuterRadius) )
return BadParameters();
if( Hollow && CapHeight>Height )
return BadParameters();
if( Hollow && (CapHeight==Height && InnerRadius==OuterRadius) )
return BadParameters();

BeginBrush( false, GroupName );



for( j = 0 ; j < WheelSides ; j++ )
for( i = 0 ; i < TubeSides ; i++ )
RHVertex3f( CentrumRadius*cos(2*j*pi / WheelSides ) + TubeRadius*cos((2*i + TubeOfs)*pi/TubeSides)*cos(2*j*pi / WheelSides ) , CentrumRadius*sin(2*j*pi / WheelSides ) + TubeRadius*cos((2*i + TubeOfs)*pi/TubeSides)*sin(2*j*pi / WheelSides ) , TubeRadius*sin((2*i + TubeOfs)*pi/TubeSides) );


for( j = 0 ; j < WheelSides ; j++ )
for( i = 0 ; i < TubeSides ; i++ )
Poly4i( +1 ,
j*TubeSides + i ,
j*TubeSides + (i+1)%TubeSides ,
( (j+1)%TubeSides )*TubeSides + ((i+1)%TubeSides) ,
( (j+1)%TubeSides )*TubeSides + i ,
'wall' );

return EndBrush();
}

[Edited by tarquin on December 27th, 2000 at 06:12 PM]

purice
27th Dec 2000, 06:36 PM
that looks very similar to the gl code i was looking at earlier.
i have to go out but i'm eager to try it out when i get back home.
nice job!

tarquin
28th Dec 2000, 06:24 PM
Compiling problems solved! Yesterday, PU had a news item leading to a german page with custom UEd buttons, and one of them was a custom builder.
One decompile later (thank you chimeric tutorials!), and I've worked out everything I need.
The torus builder is compiled and works superbly.
16*16 sides looks very impressive -- I made a simple map chaining some together. Looks great, but hell on the polycount!

Now I know what I'm doing, ideas for brush builders are welcome!
Plan so far:
1. Modified linear stair builder with an option to make the top step longer (something I often end up doing). Maybe also an option to slope the underside, like the thighpad stairs in curse][.
2. modified cylinder builder to make fractions of a cylinder.
3. spiral staircase builder that works as a subtractive brush (the current one doesn't)
But first a little break from all this coding ;)

purice
28th Dec 2000, 07:36 PM
time to make the donuts..
now i can do those vaulted ceilings in my curved hallways.
you roXor tarquin.
there's an idea i have for a brush builder, but i want to try to write it myself this weekend. it's pretty damn simple compared to the torus thing, which is why i think my dumb ass can get it to actually work.

tarquin
29th Dec 2000, 06:36 PM
Thanks purice -- and I'm not even sure what roXor means...

SlickWilly, I saw your pages explaining nodes... superb! I've been trying to find out what nodes are, and very few people seem to know. I'd noticed on Curse][ the technique of cutting a square doorway and then filling it with a semisolid arch brush.

The finished torus builder has an option to make a partial torus -- like the revolver in the 2D ed. It all works, although there are bits of the code I think are a bit inelegant and could do with streamlining, that's just me being fussy!

When I have a few more made, I'll release the thing as a pack... ETA a couple of weeks maybe.

ChrisToth.hu
29th Dec 2000, 06:51 PM
That subtractive spiral staircase would be really cool. I hate this one. It can be used only as an additive -> for what?? Tried to subtract? Hehe.

Keep up the good work.

ChrisToth.hu
29th Dec 2000, 06:55 PM
The donut brush would be very useful in my Police Station level. :D

purice
29th Dec 2000, 07:53 PM
tarquin,
i'm not even sure if you went about it this way but..

for the 'subtractive' version of the spiral stair builder:
what did you have to do besides adding in that bit about subtracting the add_to_first_step adjustment from the z component of the vtx vector in the BuildCurvedStair function?

tarquin
29th Dec 2000, 09:41 PM
I haven't started the new spiral builder yet.
The code for the Epic spiral builder looks rather scary, they use rotator objects on vectors! eek!
The code for the curved stair builder seems to use a totally different method. I think you're right, it can be easily modified. It won't do slopes though, and I dont think it goes beyond a full revolution.

With the spiral, I suspect the rotator operation is applying a matrix transformation but without documentation explaining the operators used, it would take hours of tinkering to figure it out!

Some of my torus code can be recycled for the new spiral. set tubesides to 4, add a stepheight componenent to z. Some tinkering involved because instead of 2 vertices superimposed in XY, there'll be four because of the step.
I haven't yet thought about slopes, that's another scary bit! I guess I might have to tinker with rotarors after all. Anyone know of documentation on unrealscript operators?

purice
30th Dec 2000, 12:31 PM
http://unreal.epicgames.com/unrealscript.htm

look under language funtionality..

<< int, vector Left shift (int), Forward vector transformation (vector)
>> int, vector Right shift (int), Reverse vector transformation (vector)

http://www.planetunreal.com/mutation/tutorials/vectrot.shtml
as he says it "only attempts to define vectors and rotators as viewed by the spawn function"

http://planetunreal.com/chimeric/tutorials/rotators.html

http://planetunreal.com/chimeric/tutorials/vectors.html

tarquin
30th Dec 2000, 12:59 PM
Thanks.
But what do the >> and << operators actually do to a vector?

As for rotators, I don't know whether to visualise as 3 independant orthogonal rotations, or a rotation about a single axis given by the 3 components -- I'd like convince myself that the two work out to be the same, but that'll take several sheets of paper and lots of algebra.
It's a mathematician thing. You think something's obvious, you think about it some more, and decide you need to prove it, then you end up deciding its totally false ;)

I'm going to play around with the code in the Epic spiral builder, should eventually make sense to me.

purice
30th Dec 2000, 02:53 PM
i think, like you said before, it's applying a matrix transformation..

-----------------------------------------------------
RotStep.Yaw = (65536.0f * (AngleOfCurve / 360.0f)) / NumSteps;
..
for( x = 0 ; x < (NumSteps + 1) ; x++ )
{
if( x == 0 )
Adjustment = AddToFirstStep;
else
Adjustment = 0;

NewVtx = vtx >> (RotStep * x);

Vertex3f( NewVtx.x, NewVtx.y, vtx.z - Adjustment );
vtx.z += StepHeight;
Vertex3f( NewVtx.x, NewVtx.y, vtx.z );
}
--------------------------------------------------------

each time through the loop
so that vtx's position is um..adjusted by RotStep rotator's yaw times the loop variable's value
and then set equal to NewVtx


the spiral stair, curved stair and volumetric builder all three use it.

tarquin
30th Dec 2000, 08:06 PM
The new spiral staircase buidler is on the way! A preliminary version is ready, but it doesn't do sloped ceilings or floors.
purice you're right, it applies a rotation to the vector. The << operator rotates it the other way. Multiplying the rotator, ie
vector >> ( rotator * n ) is the same as
(T^n)v or (M^n)v in linear algebra speak.
So a << is like a -n. The end result is the same as the fomulae I had with sines and cosines.
Incidentally, code you've quoted from the default builders,
vertex3f( vtx.x , vtx.y, vtx.z )
can be replaced by
vertexv( vtx )
They both create a new vertex at the position of the vector vtx. It looks neater but I suspect it's all the same to the engine.
Having said that, I made some HUGE BSP errors testing the new spiral builder. Once because I forgot to flip the direction of the polys for anticlockwise stairs, and the rest of the time because I can't count.