More B3D models problems...

BlitzMax Forums/MiniB3D Module/More B3D models problems...

SLotman(Posted 2010) [#1]


On the image above: to the left, the model if I load it with Blitz3D, or on miniB3D with LoadMesh.

If I change LoadMesh to LoadAnimMesh - the model as soon as it is moved, rotated or whatever, even using a Pivot as a parent, gets like on the right.

This is the testing code:


Since LoadMesh uses LoadAnimMesh internally... what is going on???


SLotman(Posted 2010) [#2]
Apparently it has something to do with the meshes pivot (on Max) rotation... reseting scale/transforms on them improved a lot the situation.

It looks like Blitz3D 'fixes' any rotation during loading...


GNS(Posted 2010) [#3]
Oh boy, this will be a fun one to track down I'm sure.

Few questions for you:

1). How's the model made? It looks like each body part is a separate (segmented) object. Is this the case? If so, what're the names of the individual body parts?

2). What program did you use to model the mesh?

3). Does the mesh have any bones/joints? How many?

4). What kind of video card are you running?


SLotman(Posted 2010) [#4]
As I said, the problems was with the pivots. Reseting their scales/transforms solved the issue.

The model was indeed made of individual parts. It was done on Max9.


GNS(Posted 2010) [#5]
Glad you got it sorted.


SLotman(Posted 2010) [#6]
Another issue came up. I have this model (to the left, rendered on Blitz3D, to the right, rendered on BlitzMax):



The head (where the texture is wrong), is actually 2 meshes, one slightly bigger than another. The bigger one has the eyes + mouth with alpha channel, and the small one is the colored part.

If I set the eye texture on 3DMax, its exported and rendered correctly on miniB3D. But if I replace that texture with an animated one (with code), then the problem appears. Note that both models were rendered with the same code, both on miniB3D and on Blitz3D changing the texture at code level with this:

faceTexture = LoadAnimTexture("data/models/faces.png",2,64,64,0,16)
EntityTexture FindChild(kid1Mesh, "head01"), faceTexture,0,0


Is there a problem on MiniB3D and animated textures? If I replace LoadAnimTexture with plain LoadTexture, and use a texture with a "single frame", it works! The "animated" texture is a 256x256 texture, divided into 64x64 frames - so I don't think the size is the problem...

Also, why the model on miniB3D reflect so much light, while on Blitz3D it doesn't? I tried even setting EntityShininess to 0, to no avail :(

Any help deeply appreciated!

Last edited 2010


SLotman(Posted 2010) [#7]
Found it!

On LoadAnimTexture, on this thread someone suggested a change from:

glPixelStorei GL_UNPACK_ROW_LENGTH,(pixmap.pitch/BytesPerPixel[pixmap.format])-width  


To

glPixelStorei GL_UNPACK_ROW_LENGTH,pixmap.pitch/BytesPerPixel[pixmap.format]


But this was the cause of my problems!
So does anyone knows what would be the best approach? What should be actually used, so it would work everywhere?

Last edited 2010


SLotman(Posted 2010) [#8]
Anyway - the other problem, that I mentioned: the model illumination on miniB3D... again, the same model rendered on blitzmax (on the left) and on blitz3d (on the right)



Look at the "hair" (the black thing) right side: the white reflection is much smoother on Blitz3D than on miniB3D. The same thing can be seen on a smaller scale on the arm, or in the body itself.

This white effect is made with a spheremap texture, and then calling afterwards updatenormals().

Again, any help deeply appreciated!


SLotman(Posted 2010) [#9]
I'm trying to remember some stuff here... I think the cause of that is the updateNormals functions - which is correct to an extent: it does calculate the normals for each triangle, but I'm remembering something else: a second step, which isn't implemented on miniB3D.

This second step, would attenuate the normals from on triangle to another - something like a 'normal average' of triangles next to each other.

Last edited 2010


SLotman(Posted 2010) [#10]
This new updatenormals() improves it a little bit, but still it isn't quite right (like B3D) - it's based on an old dx9 engine I was writing - but never got to finish:



Here's the result:


Maybe someone can improve it so it looks right?

Last edited 2010


SLotman(Posted 2010) [#11]
And even more problems :(

I load my model with LoadAnimMesh - then I use copyEntity to copy that model... but if I try to animate that model, miniB3D crashes on this line:

bone=ent.bones[anim_surf.vert_bone1_no[vid]-1]


This is on TAnimation.bmx, function Vertex Deform. The error is "Attempt to index array beoynd array length" - apparently when using copy entity the animations aren't copied with it? On Blitz3D animations are copied...

Edit: apparently bones *are* copied, but somehow no_bones=0. vid=0 when the crash occurs.

Edit2: anim_surf.vert_bone1_no[0] exists, so it's looking for a bone that doesn't exist on ent.bones. I used biped on 3dmax to animate the model (with skin, so the animation works) - probably it isnt copying child bones? on ent.bones I could only see the "bip01-pelvis" bone.

I have no idea what to do on this one :(

Last edited 2010

Last edited 2010


SLotman(Posted 2010) [#12]
I don't get it. I just wront a small function to dump the mesh structure, and it look ok. Here's the code:



The results are the same for both meshes:


The only difference I see from Blitz3D is that on Blitz3D every bone is created as a Pivot, not a "Bone"; but that shouldn't be the problem.

So why is it crashing? What is wrong in miniB3D CopyEntity???

Edit: hmmm... I just saw this is an old bug: http://www.blitzbasic.com/Community/posts.php?topic=74579#833500

I could really, really use a fix for that...!

Last edited 2010


SLotman(Posted 2010) [#13]
hmmm... I think I managed to reproduce it.

The problem seems to have two meshes attached to the same bone.

Here is a small package, with the code and the model (in .max 9 format, .3ds, .b3d and .fbx) that reproduces the error:

http://www.icongames.com.br/temp/minib3d-bug.zip

The model is just two boxes, and a biped. Both boxes I applied the "skin" modifier, and added the biped head as a bone.

With just one box skinned to the head, everything worked. Once I added a second box, and also skinned it to the head, then miniB3D crashed.

Last edited 2010


SLotman(Posted 2010) [#14]
No one? It would be pretty bad if I have to load my meshes over and over again, instead of just doing a copyentity... =(


Warner(Posted 2010) [#15]
When you use copyentity, the objects bones are copied as well. It seems that there is a problem with that. I think it is caused by 'CopyBonesList' in TMesh.bmx
If you compare the boneslist of the original and the copy, you see they are different:



SLotman(Posted 2010) [#16]
I see... strangest thing is that, if I do something like model2.bones=model.bones[..] or a MemCopy(model2.bones, model.bones, sizeof(model.bones)) - the error still persists.


Leon Drake(Posted 2010) [#17]
I've had the same weird issue with my models as well using max 7


SLotman(Posted 2010) [#18]
YES!!!!!!! I did it!

This is how CopyBonesList should be:


Now it works!

Only thing left to fix now is the UpdateNormals function, so it gets smooth results like Blitz3D :)

Thank you so much Warner, I wouldn't be able to fix this without your help!


Warner(Posted 2010) [#19]
No problem and good work!
About this UpdateNormals problem: In Blitz3d, I created a cube, and used UpdateNormals. Then I exported it to minib3d as data.
In minib3d, I used UpdateNormals on the same cube, and I used this program to compare the results:

There doesn't seem to be too much difference between the two. I'm thinking that maybe the minib3d updatenormals is allready pretty close the the blitz3d one. Maybe there are differences between welded/unwelded meshes? That could be something to look into. Else, it might be a difference in rendering settings instead.

Last edited 2010


SLotman(Posted 2010) [#20]
Yeah, you're right - the problem is somewhere else besides the normals... maybe the spheremap, I'll have to dig further to find out :/

Last edited 2010


SLotman(Posted 2010) [#21]
Oh man...

Just noticed another problem. After 'fixing' the copyentity problem - I found another one. If I animate the original model, the second one animates too.

If I change the animation on the second, the first one also changes. That doesn't happen on Blitz3D - you can animate each copied model independently... so, still a bug on copying the bones, or a animation bug?

Edit: Arg! It has something to do with my fix... using copyentity on the zombie model crashes, while on 'regular' minib3d it works. Back to the drawing board, I guess =(

Last edited 2010


Leon Drake(Posted 2010) [#22]
sounds like its instancing the bones and not actually making new bones.


SLotman(Posted 2010) [#23]
Now it works with both the zombie model (from the samples folder) *and* my own, with correct animations =)




Leon Drake(Posted 2010) [#24]
Awesome, i was always having issues with loading my b3d models in minib3d among another thing i can't replicate in minib3d that i can do in blitz3d


RemiD(Posted 2010) [#25]
Hello,

I don't understand all your code but i agree with this :

Maybe there are differences between welded/unwelded meshes?



When you unwrap/unweld a mesh, the unwrap program duplicates some vertices and changes their normals. Then lights affect them differently.

You can see this if you create a cube with only 8 vertices and 12 tris or a cube with 24 vertices and 12 tris.

Last edited 2010

Last edited 2010


Silver_Knee(Posted 2014) [#26]
Hey,

sorry to dig this up, but I have a similiar problem like SLotman in the first Post.

I tried to fix my model with the following:
Function FixModel(ent:TEntity)
	ent.RotateEntity 0 , 0 , 0
	ent.ScaleEntity 1 , 1 , 1
	For Local child:TEntity = EachIn ent.child_list
		FixModel(child)
	Next
End Function 


but this doesn't help. I don't know what
Apparently it has something to do with the meshes pivot (on Max) rotation... reseting scale/transforms on them improved a lot the situation.


could mean other than resetting the scale and the rotation. If I reset the position, every part of the model is in the center.

Does anyone know a solution to this?

Greez
Silver_Knee


markcw(Posted 2014) [#27]
Would really need a sample b3d to help here.


Silver_Knee(Posted 2014) [#28]
This was the model I worked with. There is no animation saved but i wanted the childs to work with them.

http://www.fs-com.com/station.B3D


markcw(Posted 2014) [#29]
Sorry but that's far too complicated a model to debug with.


Silver_Knee(Posted 2014) [#30]
Okay. But did you see the wrongly positioned elements? I'll ask my gfx guy to build a more simple model.


markcw(Posted 2014) [#31]
I wasn't able to make out what it was really.


Silver_Knee(Posted 2014) [#32]
Load it with LoadMesh then it is positioned correctly. It's a space station (without textures).


angros47(Posted 2014) [#33]
The mesh is too big, you need to scale it down by at least 0,001.

An animated mesh cannot be scaled by ScaleMesh or FitMesh, you need to use ScaleEntity. Maybe you used FitMesh...

Try loading it with LoadAnimMesh and scaling it with ScaleEntity mesh,.001,.001,.001


Silver_Knee(Posted 2014) [#34]
Huh? How can it be too big? And how can it be only too big if it's loaded with LoadAnimMesh? I'll try scaling it though as I am at home.


angros47(Posted 2014) [#35]
By default, CameraRange is 1000: if the mesh is wider, it's too big.

If you load it with LoadMesh, it will be a single mesh, and you can scale it with ScaleMesh (or with FitMesh, that works automatically); these commands don't work well if you load it with LoadAnimMesh, because it is loaded as an entity with many children, not a single mesh: ScaleMesh and FitMesh don't affect children.


Silver_Knee(Posted 2014) [#36]
I have a test code for you.
Press 1 to switch between loadmesh and loadanimmesh 2 to turn and 3 to scale down.
SuperStrict
Framework sidesign.minib3d

Const FILENAME:String="station.b3d"

Graphics3D 800 , 600 , 32 , 2

Local camera:TCamera=CreateCamera()

CreateLight()

Local a:TMEsh = LoadMesh(FILENAME)
Local b:TEntity = LoadAnimMesh(FILENAME)

PositionEntity camera,0,0,-1000

HideEntity b

Local show:Byte=0
DebugLog "go"
Repeat
	If KeyHit(KEY_1)
		If show
			ShowEntity a
			HideEntity b
			show = 0
			DebugLog "a"
		Else
			HideEntity a
			ShowEntity b
			show = 1
			DebugLog "b"
		EndIf
	EndIf
	
	If KeyDown(KEY_2)
		TurnEntity a,0,1,0
		TurnEntity b,0,1,0
	EndIf 
	
	If KeyHit(KEY_3)
		ScaleEntity a,0.001,0.001,0.001
		ScaleEntity b,0.001,0.001,0.001
		PositionEntity camera,0,0,-2
	EndIf
	RenderWorld
	Flip
Until KeyHit(KEY_ESCAPE) Or AppTerminate()
End 


As you see the entity, that was loaded by loadanimmesh, is scrambled after TurnEntity is used on it the first time. Maybe this has something to do with the Matrix of the sub entities that aren't set up correctly.

@angros47 I've never used a Mesh-Command such as FitMesh/ScaleMesh/RotateMesh I always used Entity-Commands. I also don't have a problem seeing it; it's scambled just like the figure in OP.


angros47(Posted 2014) [#37]
I made my tests under OpenB3D; I'm not sure about what happens in minib3d.


Silver_Knee(Posted 2014) [#38]
Here is another, more simple model, that gets the same error:

http://evolver.bplaced.net/pyra.rar


Leon Drake(Posted 2015) [#39]
yea i just bought Ultimate unwrap cause i didn't want to deal with this anymore, same thing happens on minib3d for monkey


Kryzon(Posted 2015) [#40]
Almost every engine that is used on published games have some form of a standard asset pipeline.
If you have to go in circles just to import your assets then that shows that there's something really wrong.
A game SDK is supposed to let you work smarter, not harder.


Leon Drake(Posted 2015) [#41]
blitz3d has some terribad pipeline, i made a working Cal3d library for minib3d. just need to polish it off but i do love being able to use the physique modifier and make use of spring systems for loose clothing and hair.

but i still need to optimize it a bit because i have to generate the vertices changes and push them into the VBO of a b3d mesh object every frame.