surface -> triangle?

Blitz3D Forums/Blitz3D Programming/surface -> triangle?

Mustang(Posted 2006) [#1]
Ok, just a quickie... how do I paint/apply certain surface/brush to certain triangle? For example I have created two textures and want to apply textures to the triangles depending how the face etc? Code archives probably has something like this already but I though if someone would have a quick answer. Also what if the triangle is multitextured, how to control that with individual triangles?

EntityTexture entity,texture[,frame][,index][,triangle_index] would be so handy but most Blitz commands are mesh wide... I need individual triangles for targets.


Avon(Posted 2006) [#2]
So far as I know, you can't apply textures to single triangles, only surfaces. You need a brush to do this. I wrote a "TextureSurface" function a while back, but the code is at home. I'll paste it in here tonight, if you are interested.

In the meantime, from memory it works something like this:

mesh = LoadMesh("mesh.3ds")
texture = LoadTexture("texture.png")
brush = CreateBrush()
BrushTexture brush, texture
surface = GetSurface(mesh, 1) ; 1 = surface index, ranges from 1 to No. of surfaces in mesh
PaintSurface surface, brush



big10p(Posted 2006) [#3]
As Avon says, you can only apply textures on a per surface basis, not per triangle AFAIK.

So, the only ways I can think of to achieve what you want is to either sort all triangles into separate surfaces, or combine your textures into one large texture and UV map each tri appropriately. However, even then you'll probably have to unweld a load of tris to get the effect you want.

That's a lot of fiddling and hassle so probably isn't a practical solution. Best I can think of, though.


Mustang(Posted 2006) [#4]

As Avon says, you can only apply textures on a per surface basis, not per triangle AFAIK.



Yup, I know that, but I want per triangle... and like you and Avon said, it's certainly possible. And here's how:

http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=433

I should have checked the archives more throughly in the first time... what ever you want to do, it's probably there :)


Avon(Posted 2006) [#5]
Wow... nice find! That TeraBit is a clever fellow.


big10p(Posted 2006) [#6]
Nice find. The code arcs are a goldmine. :)

Quick look at the code looks like he's unwelding all the tris which I 'spose is the only practical way to do it.


Mustang(Posted 2006) [#7]
Just tested it - it even works! :)

[Well so far I have not seen any code from TeraBit that would not work...]


Beaker(Posted 2006) [#8]
You just have to remember to re-weld all same textured triangles into a one surface, otherwise you will have one surface per triangle which could get very slow.


big10p(Posted 2006) [#9]
Yeah, that's what I meant when I said "sort all triangles into separate surfaces". Not a very clear way of putting it, I'll admit. :)


Mustang(Posted 2006) [#10]

You just have to remember to re-weld all same textured triangles into a one surface



Now correct me if I'm wrong but TeraBits code does that? Check the "AddTriangle dest,vertind,vertind+1,vertind+2
... UpdateNormals pmesh" part.


Beaker(Posted 2006) [#11]
Yes it does. Sorry, I didn't look at the code before posting. :)


Beaker(Posted 2006) [#12]
Something I just noticed tho is that it doesn't attempt to re-weld the vertices (altho it does weld tri's into one surface). For that you will need this:
http://www.blitzbasic.com/codearcs/codearcs.php?code=454


Mustang(Posted 2006) [#13]
Ah - thanks for the heads up! I'll add that code.


Beaker(Posted 2006) [#14]
Updated version posted here:
http://www.blitzbasic.com/codearcs/codearcs.php?code=433#comments


Mustang(Posted 2006) [#15]
:) Thanks!