Loading a Multitextured Mesh

Blitz3D Forums/Blitz3D Programming/Loading a Multitextured Mesh

AvestheFox(Posted 2010) [#1]
Okay, so I have a slight problem when it comes to loading a multi-textured mesh into B3D.

Some of my textures have alpha channels, but I don't know how to get the program to read those flags. I've tried loading the textures into the code and reapplying them to the mesh (setting the alpha flags to the proper textures) but all that does is stack all the textures on top of each other.

I really don't want to have to put all the textures into one file, because I cant easily set the texture repeats without another texture partially overlapping the wrong surface.

Suggestions?


Leon Drake(Posted 2010) [#2]
the only way i can get it to work is to make sure they are png files...

but from what it sounds like your trying to make some sort of blended texture with one detail map that fades into another detail map using an alpha layer in between them right? i think i did that before with a terrain i was making. it doesn't work super great but it looks nice if you get the order correct.

i'll see if i can't find the code i used to get it to show up right.


AvestheFox(Posted 2010) [#3]
all my textures are in png format. Here's a test mesh both in AC3D (my choice 3D editor) and in Blitz3D



Notice, in AC3D the fence is perfectly transparent. But in Blitz it is not. I've tried reloading the texture in the code and setting the texture flag "2" but reapplying the texture to the mesh puts the texture on the entire mesh...




Leon Drake(Posted 2010) [#4]
found it. So far to create this here



which was just 2 different detail maps(tiled) and two alpha masked textures stretched across the terrain.

bbTextureBlend(colormap,5)
bbTextureBlend(maskmap,1)
bbTextureBlend(detailmap2,2)
bbTextureBlend(detailmap3,2)
bbTextureBlend(maskmap2,1)



bbEntityTexture(mainterra,maskmap,0,5)
bbEntityTexture(mainterra,detailmap3,0,4)
bbEntityTexture(mainterra,colormap,0,3)
bbEntityTexture(mainterra,maskmap2,0,2)
bbEntityTexture(mainterra,detailmap2,0,1)
bbEntityTexture(mainterra,colormap,0,0)



depends on the order, the way multitexturing works your probably only going to get 2 detail maps to work before its starts getting to dark or weird looking. What i had to do was merge a stretched color onto the tiles detail map layer using multiply, then the next layer would mask part of the detail map. then i would do it again add a color map to the next detail map then mask it. the final result was the pic above.


Leon Drake(Posted 2010) [#5]
ah well perhaps its the way the texture is blended and the order of the texture..


AvestheFox(Posted 2010) [#6]
lol, yeah, I know about that kind of texturing :) I've used it to apply scrolling cloud shadows on hightmap terrains before. Cool stuff!

But unfortunately, that wasn't what I was looking for. :P

thanks anyway!


Leon Drake(Posted 2010) [#7]
perhaps you should use paintsurface instead of entity texture.

making the fence one surface and the ground another.


AvestheFox(Posted 2010) [#8]
That would require me to dissect the whole mesh (Mind you, I'm not very good at working with entity children in coding just yet...)

What I'm trying to do is load an entity that has more than one texture and keep all the texture flags in the order they were in when they were applied in the 3D editor.

that test mesh has only three textures (grass,wall,fence) the fence is the only texture that has an alpha flag to it.


AvestheFox(Posted 2010) [#9]
Actually, scratch that. I seem to be a bit slow today. I see what your saying about finding surfaces and applying the texture to said surface.. But say on a large scale map, that would take quiet an effort... :P


AvestheFox(Posted 2010) [#10]
Then again... I'm rather new to surface editing in Blitz3d

Forgive my ignorance :P


Leon Drake(Posted 2010) [#11]
its not that hard really,



'make some array of brushes
local brush[2]


s = countsurfaces(mesh)

for i = 1 to s

surf = getsurface(mesh,s)
surfbrush = GetSurfaceBrush(surf)

'add the textures to the brush here, or make a new brush

PaintSurface(surf,surfbrush)

next




If you exported a mesh that uses multiple textures. like using a Multi-sub object modifier or actually painint a different texture on different faces, then usually when its exported as a B3d file it will create a surface for each texture on the mesh. So if you block has an upper fence as one texture and the lower half is the ground, both of which use different textures then your mesh should contain multiple surfaces.


that's pretty much it. if its a bone rigged animated mesh then you have to do a little more digging to get to the actual child that contains the surfaces.


AvestheFox(Posted 2010) [#12]
Before I saw your post I had started to experiment with the camerapick and pickedsurface commands. Your right! the surface is labeled pretty much by the texture that it is using.

So I found the label# for the fence surface and repainted the texture to it. It worked! :)

I wish I had researched this sooner. But I'm glad I have it now.

Thanks for the help!


Ross C(Posted 2010) [#13]
Why not use the texture filter command? It will apply flags to any texture with a certain file name


Ross C(Posted 2010) [#14]
http://www.blitzbasic.com/b3ddocs/command.php?name=TextureFilter&ref=3d_a-z


AvestheFox(Posted 2010) [#15]
Actually, that's even better than the last solution! Thanks Ross!

though now I have a new problem...



It appears that the alpha textures are inside out. Or something to that effect...


_PJ_(Posted 2010) [#16]
That's odd.
Seems like something Z-Buffer related, since the 'back' two sides of the fence seem to have been drawn IN FRONT of the front ones.

If that's all it is, it might not be too hard to fix, but what's really strange in that, though, in your original B3D (and the AC3D) they were drawn in the correct order.

Sorry, this may be kinda obvious and all and I really don't know anything that might be more helpful :S


Kryzon(Posted 2010) [#17]
You must have used the "Disable Backface Culling" brush FX. It screws the Z Ordering. Either disable this FX, or duplicate each fence side and flip it (in AC3D, of course).

Regarding the first problem you posted the comparison screenshots for, it makes me think it's related to the B3D exporter you're using.

Try downloading the freeware Blender3D and using the GandalDF plugin to export B3D meshes with each texture already flagged properly.

I use the B3D Pipeline for exporting my models - it's only available to 3DS Max. But what it allows you to do is configure each texture flag individually, for each Brush (that's what you should be doing, if your exporter allows such a thing. You should always avoid having to re-texture things through code). The B3D file format allows for each texture to have its flags inside the file, so there's no reason your exporter won't allow you to set up the flags while in the 3D editor.

The more work you do on the 3D editor and remove from doing it from code, the better (why? because then you'll have to worry only with a single LoadMesh() and not a whole paragraph of code).


AvestheFox(Posted 2010) [#18]
I'm exporting my models in the Direct X ".x" format from AC3D.

I do have a copy of Blender saved on my thumbdrive. But the last time I tried to download gandalDF's B3D plugin, the link was broken...

I've been bugging the heck out of the guys over at inivis.com (the website for AC3D) to create a B3D exporter for their software, but there's never really a reply :P

I'll play around with the culling flag and see what I can do with it.


Kryzon(Posted 2010) [#19]
If you're doing a more complex project, you really need that control over your exported models.
Try to find another hosted file of the GandalDF's (and good luck with your game).


Leon Drake(Posted 2010) [#20]
why not make a quick converter using the bbfile.bb source to resave the model you loaded to a b3d file?

luckily i just so happen to have it right here ;)

http://www.vigilsoft.net/b3dfile.zip


ardee(Posted 2010) [#21]
I have the last release of GandalDF's Blender b3d exporter, which according to the licence can be redistributed. I can send it to you if you want.


AvestheFox(Posted 2010) [#22]
@Leon Drake: Cool! I'll give it a go :)

@Ardee: Its much appreciated but I found a link on some forum that let me download it. I'm clueless on how to install it (or how to use Blender period :P ) but its something I'll just have to invest my free time in when I get around to it. Your offer is much appreciated!


Kryzon(Posted 2010) [#23]
It's worth the effort, Avest. I'll tell you that much. (EDIT: Regarding the pipeline, though. I've never used GandalDF's).


AvestheFox(Posted 2010) [#24]
@Kryzon: I'll take your word for it. I'm looking up how to install the extension to blender now :P


Kryzon(Posted 2010) [#25]
Hi Avesthe, try this: http://web.archive.org/web/20080803033043rn_1/www.gandaldf.com/specs-english.html (look on the right side =P )


AvestheFox(Posted 2010) [#26]
I've done all the steps on that page right up to "run script" I'm not exactly sure how to do this :P

I'm in the Python command prompt window if that helps my situation much


Kryzon(Posted 2010) [#27]
http://www.macouno.com/2010/03/17/using-python-scripts/ - Using Python Scripts in Blender.


AvestheFox(Posted 2010) [#28]
Alright, I got it scripted, but next problem: faulty exporter. When I try to export as a b3d I get a Python error.. I may need a none faulty b3d script :P

anybody willing to share theirs?


Ross C(Posted 2010) [#29]
About your previous error regarding the drawing order. Use the mask flag, rather than the alpha flag.


ardee(Posted 2010) [#30]
You need a full python install to use this script

http://www.python.org/

The console will tell you what series of python Blender was compiled with - you need the corresponding version of python.


AvestheFox(Posted 2010) [#31]
@Ross: That did indeed solve the z-order problem (which I should say, your suggestion was a godsend!) But what if I want to apply alpha textures with stained glass effects, or I have my textures anti-aliased (or blurred) and I want that effect to show true on the Blitz3Ded texture? masking gives these kind of textures a nasty outline, or blanks some areas out where the color values>0 .. still, it'll work for something as simple as a fence texture :)

@Ardee: Thanks! Downloaded now, about to install. :) Should be easy to install to the portable version of Blender (I hope)


RifRaf(Posted 2010) [#32]
that did indeed solve the z-order problem (which I should say, your suggestion was a godsend!) But what if I want to apply alpha textures with stained glass effects, or I have my textures anti-aliased (or blurred) and I want that effect to show true on the Blitz3Ded texture? masking gives these kind of textures a nasty outline


Avesthefox,

This problem is most notable when you have alpha blended surfaces in the same model. Try saving your model grouped, and then use LoadAnimMesh() instead of Loadmesh() , perhaps that will help with the zorder issue & alpha blending.


AvestheFox(Posted 2010) [#33]
@RifRaf: I see what your saying and did as you suggested, but it doesn't seem to be working...

I've tried all three formats too, b3d,x and 3ds (b3d and 3ds do not disable culling all that well when loaded with loadanimmesh)

I separated the fence from the ground and made them seperate groups. Heck I even tried ungrouping and naming all four fence sides seperately. No luck! And I'm starting to think that .x is not seperating groups all that well (attempted some getchild codes in that format with failing results)


AvestheFox(Posted 2010) [#34]
countchildren has confirmed that my .x exporting makes all entities as one mesh :P ... unfortunately, this is the only format that seems to work correctly when disabling culling under loadanimmesh.


Ross C(Posted 2010) [#35]
Have you tried ultimate unwrap? Very easy to use and the blitz exporter is excellent. It def exports groups.


AvestheFox(Posted 2010) [#36]
Downloading it now. Seeing that its the demo version, I have to ask. Is it a timed trial version?

And also, is the ability to export infinitive? I mean, is it limited?


Kryzon(Posted 2010) [#37]
this is the only format that seems to work correctly when disabling culling under loadanimmesh.


Why are you disabling it in the first place? I told you that it screws the Z-Order (I've had some problems with fences with this as well, I'm not speaking out of nowhere).

Instead of disabling the backface culling ('either' with EntityFX or BrushFX), copy each fence side and flip it (so as to have the same result as disabling backface culling).


AvestheFox(Posted 2010) [#38]
I wasn't ignoring you when you suggested that. I just wasn't sure whether I liked the idea or not. But now that I've tried it, it seems to be the best solution for that problem.

Forgive me if I seemed to be ignoring your advise earlier

But hey, I tried it and it works! For that I am very thankful! :)

@Ross: I got UW up and running and the B3D plugin installed for it. But how the heck to I export it? Please dont tell me its in the save option... that's been disabled for the demo :(

Edit: and to those who are wondering, yea I got Blender's exporter working too, but for me its not wielding the desired results :(


Kryzon(Posted 2010) [#39]
Ok, no problem (I might have sounded a bit more agressive just now...sorry).

EDIT: This might be another solution, Gile[s]:

http://www.frecle.net/index.php?show=&section=giles&sub=about

it seems to enable you to re-texture\change blend and FX flags of the materials inside the model, and to import a lot of formats (only static meshes, though, so you'd be using this for level design only). And it exports to a fully compatible .B3D (it was made by a blitzer).

For animated ones you'd be depending on GandalDF or PaceMaker, really. (I don't know if UUW3D can import\export animated meshes).


AvestheFox(Posted 2010) [#40]
That's a nice little piece of software :) pretty straightforward too!

At the moment I'm toying around with Blender's B3D exporter. I'm learning methods on how to use it correctly. A few times I've had trouble with the zorder (again) even with the fence surface duplicated and flipped. But I seem to have it fixed now.

I'm exporting the model from AC3D in the regular AC format and exporting it directly into Blender and from there exporting it to B3D. Since the ac file keeps everything accurate throughout the transfer the B3D format seems least messed up than it was when I was exporting from AC3D as a 3ds.

The only problem I'm having now is getting Blitz to find the mesh children.

But aside from that, everything is smooth riding :)


RifRaf(Posted 2010) [#41]
The only problem I'm having now is getting Blitz to find the mesh children.


debug the model in blitz and see whats up.


main=laodanimesh("whatever.b3d")
Ccount=CountChildren(main)
For c=1 To ccount
	DebugLog EntityName$(GetChild(main,c))
Next



AvestheFox(Posted 2010) [#42]
oy...

Apparently its not saving the names of the groups I created in AC :P

its all shape names ("rect,rect2,rect3,etc")

Edit: Well, while it may not be able to read as whole groups, its at least reading everything else. So its a good thing :)


Ross C(Posted 2010) [#43]
Yeah i'm afraid exporting is disabled but the paid for version is well worth it. I keep forgetting about Giles...


Leon Drake(Posted 2010) [#44]
you can find every single child with this code



Type child

Field child,childcount,parentmesh

End Type


Function getchildren(ent)
	entp = ent
	While ent
	c.child = New child
	c\child = ent
	c\parentmesh = entp
	ent = NextChild(ent)
	Wend

End Function


Function NextChild(ent)
		Local siblingcnt
		If CountChildren(ent)>0
			Return GetChild(ent,1)
		EndIf
	
		Local foundunused=False
		Local foundent = 0, parent,sibling
		While foundunused=False And ent<>0
			parent = GetParent(ent)
			If parent<>0
				If CountChildren(parent)>1
					If GetChild(parent,CountChildren(parent))<>ent
						For siblingcnt = 1 To CountChildren(parent)
							sibling = GetChild(parent,siblingcnt)
							If sibling=ent
								foundunused = True
								foundent = GetChild(parent,siblingcnt+1)
							EndIf
						Next
					EndIf
				EndIf
			EndIf
			ent = parent
		Wend
		Return foundent
End Function