B3D models not rendering right...

BlitzMax Forums/MiniB3D Module/B3D models not rendering right...

SLotman(Posted 2010) [#1]
To the left the model rendered on B3D, to the right, the same model, on miniB3D.

On this first image, you can see the tire is rendered wrong - the interior of the tire is being rendered outside!
http://a.imageshack.us/img687/2681/minib3d001.jpg

On the second image, some meshes that should be invisible are being rendered (look the white parts on the right)
http://a.imageshack.us/img15/7076/minib3d002.jpg

On this third final image, lots of wrong things: the tree is rendered on wrong order (behing the cement square, when it should be on top of it - you can't even see the tree roots) - and some misterious green thing is showing up on the sewer...
http://a.imageshack.us/img203/3694/minib3d003.jpg

All modles were made on 3DMax 5, exported with B3Dexport, and do work without any kind of problems on original B3D.

Does anyone know what could be the problem? Something not supported on B3D loader?


SLotman(Posted 2010) [#2]
I think part of the problem - at least what concerns image #2 - is the loader isn't somehow taking into account brush alpha. The 'white parts' on the second image have a brush assigned to them with 0 alpha - which is even read on TModel:LoadAnimB3D - but somehow is lost during rendering.


Hujiklo(Posted 2010) [#3]
Unfortunately brushes and alphas are not yet working reliably in miniB3D - which makes it pointless to try to make a game with in its current state, unless you can find the bugs in the source code and fix them. I gave up with my game. This engine has no official support.

Check out the other 'alpha' & 'brush' related threads in this minib3d forum for more info.


ima747(Posted 2010) [#4]
set the object's alpha to 0.99 rather than 1.0 to force it to alpha blend, see if that makes any difference. There is also an entity FX flag to force it to render with alpha, as well as one to force it to use BRUSH alpha rather than object alpha.


SLotman(Posted 2010) [#5]
Fixed the white parts on image 2! Changed 'Method Alpha' on TMesh.bmx from this:



To this:



And now the second image is correct. No clue yet about the first and third :/


Kryzon(Posted 2010) [#6]
@Alpha problem: I don't know why your Alpha function is different than mine (it's the Small Fixes version), but mine has this:

If surf.brush.alpha#<1.0 Or surf.brush.blend=2 Or surf.brush.blend=3 Or surf.brush.fx&32
I guess just checking if it's less than 1.0 suffices any alpha blending case.

@Tire: is the tire's interior a separate mesh?


simonh(Posted 2010) [#7]
MiniB3D still does have official support. It hasn't been updated much recently as I have been extremely busy releasing gerball, but I'm ready to go back to it now and tidy it up a bit.


Hujiklo(Posted 2010) [#8]
If it's official then why not charge for it? It's begging to be sorted out properly. I think everybody comfortable with Blitz3D would pay to have minib3d as their bmax 3D engine.


SLotman(Posted 2010) [#9]
@Alpha problem: I don't know why your Alpha function is different than mine (it's the Small Fixes version)

I like to experiment with things here :)
But in any case, my 'experimental' version is a separated mod, so I can test the official and mine to see if I haven't broke anything :)

@Tire: is the tire's interior a separate mesh?

Nope. What I can understand is that there are meshes being rendered with alpha, when they should be rendered normally - forcing tmesh.alpha to return false, the tire and the tree render correctly - but then, meshes with brush.alpha=0 that shouldn't be rendered appear on screen.

Even with my 'fix', the green things on the third image still appears.

The difference is that on second image, the 'white geometry' has no texture on the brush - while on the third the 'green thing' is also a brush with alpha=0, but it does have a texture assigned to it.


SLotman(Posted 2010) [#10]
Look at this:



On the left, the normal render. The grass shouldn't be rendered (brush.alpha=0) and the trash can is rendered wrong - you can see the back handle being rendered - but the trash can have brush.alpha=1, so it shouldn't use alpha.

On the right, I force tmesh.alpha=false, so you can see the trash can being rendered right, but still, the grass shows.


SLotman(Posted 2010) [#11]


I got some improvements... don't know exactly why, but with the code below, the first and the second screens are rendering right (the tire is correct), and the third gets like the screenshot above - the tree is rendered right, the trash can is right - just the grass that shouldn't be rendered continues to show.

Here's my 'new' TMesh.Alpha method:



SLotman(Posted 2010) [#12]
I think I understand now.

MiniB3D is rendering the whole scene as a single mesh, altough it's one 'scene root' and many meshes parented to it.

So, I did another quick hack, and added this on TModel.LoadAnimB3D, just before "Return TMesh(root_ent)"

		For Local f:Int=1 To CountChildren(root_ent)
			Local e:TEntity = GetChild(root_ent,f)
			Local s:TSurface = GetSurface(tmesh(e),1)
			Local b:TBrush = GetSurfaceBrush(s)
			
			EntityAlpha e,b.alpha
		Next


After that, I returned TMesh.Alpha code to 'normal'. Now the grass is gone, and all levels are being rendered correctly.

This problem should really be looked into - this 'way' of exporting meshes with b3d pipeline (several meshes, all attached to a scene root), is even the recommended one by the pipeline itself, so it should be rendered right... I just don't know how to do it, unfortunately.


Kryzon(Posted 2010) [#13]
Nice spotting :)

I'm sure there must be a way to include that code inside the file-tag-reading part, just so you don't need a second For...Next loop (even if it's a fast one).
Just to make it more elegant.

This problem should really be looked into - this 'way' of exporting meshes with b3d pipeline (several meshes, all attached to a scene root), is even the recommended one by the pipeline itself, so it should be rendered right... I just don't know how to do it, unfortunately.

Well, I would see the only benefit of having everything as a separate mesh (or child under the same Scene Root) in the fact that each one can have a seperate Brush and Texture. Also, if you ever think about moving each one separately.
But on the technical aspect, having everything batched into the same Vertex Buffer is much faster (since each glBindTexture() costs quite some time).

So, if using a texture-atlas is outside the scope of your project (and force of will... because it's hard as hell to map something with this), then having them as separate things works as well.


SLotman(Posted 2010) [#14]
Yuck

Apparently the problem isn't solved by my 'fix' - the problem isn't on loadanimmesh!

If I load my model with loadanimmesh, it is rendered right - but if I load it with LoadMesh, it goes bananas!

I really think the problem is that LoadMesh does this:

	Local ent:TEntity=LoadAnimMesh(file$)
		
	ent.HideEntity()
	Local mesh:TMesh=TMesh(ent).CollapseAnimMesh()
	ent.FreeEntity()


So the actual problem lies in this CollapseAnimMesh function...