GetSurface ????

Blitz3D Forums/Blitz3D Programming/GetSurface ????

Jack(Posted 2005) [#1]
I've been using the Demo for some type doing some work and just purchased the "Real" version and of course now I find that what I thought was working is not.Here is the deal.

I have a mesh with 4 surfaces.It was made and textured in milkshape.What I need to do is that when an object hits on a surface then find what surface that is and apply different factors to the object.

Okay,so I get the handle with "GetSurface" and if I know what that handle represents I am OK.Problem being the handle changes (I don't know when but it does) and now what was surface#1 may be surface#3,or not.

I've programmed in VisualBasic for 15 or so years but must admit using handles is really something new to me.I must be missing something very basic here.

Sure would appreciate so insight on this and how to do the thing right.How the heck do I know what surface the "handle"represents?

Thanks


DJWoodgate(Posted 2005) [#2]

I must be missing something very basic here.



It's a little idiosyncracy. I don't think you can rely on surfaces loading in the same order each time. (Don't ask me why, there must be some good reason for it, but I can't think what). Further, surfaces that are textured the same and have other identical brush properties will be combined. But from what you say I assume your surfaces have different properties. So build brushes with those properties and then use findsurface(). Not something I have tried myself mind, but presumably it will work (fingers crossed).


Jack(Posted 2005) [#3]
David - thanks for the quick response.

Basically your description is as I understand handles and the surfaces do have different textures.

Problem is they are applied in Milkshape so I really have not created brushes for applying them.

If I am not mistaken the manual mentions that you must use GetSurface before you can use other commands on a particular surface so I guess the handles must be of some value in figuring out exactly what surface is contacted.

Surely there is a way of doing this??????????


DJWoodgate(Posted 2005) [#4]
The handles as such are just pointers to memory addresses that store the surface structures.

If the surfaces do have different textures then you can go through them using Getsurfacebrush(), Getbrushtexture() and texturename() functions to establish which surface is which.


Jack(Posted 2005) [#5]
Well - that willl work but wow - what a bunch of steps.

But it works.Thats what counts.And the code below doesn't include stripping the path info.Doing it just once when the program is run .will be no problem.

Yea,I know;loops & paths & arrays will simplify it but I'm just making sure I get an answer now.

By the way , I did think of another way that sorta fudges it.Counting the verts in each surface ,if you know about how each surface relates to each other will let you get an answer.

I guess I didn't realize there was still a "brush" involved even though I textured the surfaces in milkshape. IShould have.

Dave - Thanks a lot. I appreciate your help a bunch.

sur1=GetSurface (f,1)
sur2=GetSurface (f,2)
sur3=GetSurface (f,3)

testem1=GetSurfaceBrush(sur1)
testem2=GetSurfaceBrush(sur2)
testem3=GetSurfaceBrush(sur3)

test1tex=GetBrushTexture(testem1,0)
test2tex=GetBrushTexture(testem2,0)
test3tex=GetBrushTexture(testem3,0)


jfk EO-11110(Posted 2005) [#6]
(FindSurface ?!? I even didn't know this exists, does it?)

Anyway, the way using GetsurfaceBrush, GetBrushTexture and TexureName is th eway to go, but there is one thing you should consider: these function will create copies of the things you are checking, so you need to free the resources after usage. (texture and brush)

You could write a function that takes a texturename as a string and returns the number of the surface that is using the texture, or eg. -1 when the texture is not used.


DJWoodgate(Posted 2005) [#7]

(FindSurface ?!? I even didn't know this exists, does it?)


Oh yes.
http://www.blitzbasic.co.nz/b3ddocs/command.php?name=FindSurface&ref=3d_a-z

Probably not used very much though. All well and good if you have built something in Blitz because you will already have the brush, but I can see it is going to be a pain to construct a brush that has the same properties as say a material applied in milkshape. Though I guess you could get the brush for the first surface and then modify this accordingly for surface retrieval if, for instance, only the surface color was a distinct feature.

So I have not used it. Perhaps I should just to make sure it does work :)

Its another option, and as Jack says if you know the vert counts for each surface and these are unique then by all means use that instead. Darn sight quicker I should think. At the end of the day it is finding some unique feature that distinguishes each surface. Be nice and easy if surfaces were always loaded in the same order of course.


Jack(Posted 2005) [#8]
Here is an alternate method (probably a lot faster) way to solve the problem as long as you can get and apply the right vert quantity in code while constructing the program.

It was my understanding that the "handle" would not change once program started but it could be different with each exectution.Thus the original problem.

However - I would swear ,not sure though, that I saw it change once during executuin.Anyone know about this for sure.

Anyway - I plan on using both solutions at the same time just as a fail safe.

;;Due before Main Loop
sur1=GetSurface (f,1)
sur2=GetSurface (f,2)
sur3=GetSurface (f,3)
turf(1,1)=CountVertices(sur1)
turf(2,1)=CountVertices(sur2)
turf(3,1)=CountVertices(sur3)

;;Do in main loop when surface hit is needed
whatsurface=PickedSurface():surfacehit=0
vertnumb=CountVertices(whatsurface)
If vertnumb =1159 Then surfacehit=1
If vertnumb =4203 Then surfacehit=2
If vertnumb =8878 Then surfacehit=3


jfk EO-11110(Posted 2005) [#9]
Of course, when you know the surface count, it may be a more direct way. But usually I only see the texture files and don't want to check the vertices count.

Additionally, the texture name way allows to check eg. if a substring may be part of a filename, eg. darkgrass4.jpg would contain the substring "grass" and could trigger special footstep sounds.

and findsurface requires to know the brush-handle - pretty useless in this situation imho. Anyway, there are many ways to rome, as some people say :)