miniB3D - .obj - .b3d???

Monkey Forums/Monkey Programming/miniB3D - .obj - .b3d???

Amon(Posted 2013) [#1]
I have an animated .b3d model I exported from UUnwrap which originally was a .fbx.

Basically I'm reading a whole lot of mixed information regarding the format models need to be in in order to load them in to minib3d.

With .b3d files (animated or not) what do i need to do preparation wise to get them to load correctly in Monkey-minib3d?

Ta.

P.S I would search the forum but it's like I said above, there seems to be a whole load of mixed info.


AdamRedwoods(Posted 2013) [#2]
any files you need to load need the
#BINARY_FILES="*.obj|*.b3d"

in the beginning of the file.

.b3d can be binary now, all targets seem to work. no base64 is needed.
.obj is text, but should work regardless.

if you have problems with a specific file, let me know. remember to preload your textures if you're planning on using html5 or flash.


Amon(Posted 2013) [#3]
Hi! I'd like to send you the b3d model. I've tried many things but all I get is a black screen (glfw, html5, android) etc.

Your profile email is not viewable. Where can I send the model with textures?


Amon(Posted 2013) [#4]
No idea what I'm doing.

#If TARGET="win8"
	#WIN8_PRINT_ENABLED=(CONFIG="debug")
	#WIN8_SCREEN_ORIENTATION=15				'bitwise OR of: 1=portrait, 2=landscape, 4=portrait flipped, 8=landscape flipped
	
	#MOJO_AUTO_SUSPEND_ENABLED=False
	#MOJO_IMAGE_FILTERING_ENABLED=True
	
	#TEXT_FILES="*.txt|*.xml|*.json"
	#IMAGE_FILES="*.png|*.jpg"
	#SOUND_FILES="*.wav|*.mp3"
	#MUSIC_FILES="*.wav|*.mp3"
	#BINARY_FILES="*.bin|*.dat|.obj|*.b3d"
#EndIf

#If TARGET="glfw"
	#GLFW_USE_GCC=False
	#GLFW_WINDOW_TITLE="test"
	#GLFW_WINDOW_WIDTH=1024
	#GLFW_WINDOW_HEIGHT=768
	#GLFW_WINDOW_RESIZABLE=false
	#GLFW_WINDOW_FULLSCREEN=false
	#TEXT_FILES="*.txt|*.xml|*.json"
	#IMAGE_FILES="*.png|*.jpg"
	#SOUND_FILES="*.wav|*.mp3"
	#MUSIC_FILES="*.wav|*.mp3"
	#BINARY_FILES="*.bin|*.dat|.obj|*.b3d"
#EndIf

Strict

Import minib3d.app
Import mojo


Function Main:Int()
	New GZombies()
    Return 0
End
 
Class GZombies Extends MiniB3DApp

	Field fpsRate:Int = 30
	Field init_gl:Bool = False
	Global ZombieTexture:TTexture[5]
	
	Field zombie:TMesh
	Field cam:TCamera
	Field light:TLight

	
	
	Method Create:Int()
		SetUpdateRate(fpsRate)
		SetRender()
		PreLoad("models/Zombie_1.jpg, models/Zombie_2.jpg, models/Zombie_3.jpg, models/Zombie_4.jpg, models/Zombie_5.jpg")
		Return 0
	End
	
	Method Init:Int()
		SetFont(LoadImage("mojo_font.png", 96, Image.XPadding))
		ZombieTexture[0] = LoadTexture("models/Zombie_1.jpg", 1)
		ZombieTexture[1] = LoadTexture("models/Zombie_2.jpg", 1)
		ZombieTexture[2] = LoadTexture("models/Zombie_3.jpg", 1)
		ZombieTexture[3] = LoadTexture("models/Zombie_4.jpg", 1)
		ZombieTexture[4] = LoadTexture("models/Zombie_5.jpg", 1)
		
		zombie = LoadAnimMesh("models/zombie.b3d")
		
		zombie.PositionEntity(0, 0, 0)
		
		If Zombie.list <> Null
			Local z:Zombie = New Zombie
			z.Create(10)			
		EndIf
		cam = CreateCamera()
		light = CreateLight()
		cam.PositionEntity(0, 4, -10)
		Return 0
	End
	
    
	Method Update:Int()
		
		#If TARGET <> "win8"
			If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then EndApp()
		#EndIf
		
		If Zombie.list <> Null
			For Local z:Zombie = EachIn Zombie.list
				z.Update()
			Next
		EndIf
		
		
		
		
		If KeyHit(KEY_LEFT)
			fpsRate-=5
			SetUpdateRate(fpsRate)
		End
		If KeyHit(KEY_RIGHT)
			fpsRate+=5
			SetUpdateRate(fpsRate)
		End		
		
		Return 0
	End

	Method Render:Int()
		Init()
		SetMojoEmulation()
		
		light.LightColor(255, 255, 255)
		light.PositionEntity(0, 30, 0)
		
		Return 0
	End
End

Class Zombie
		Global list:List<Zombie>
		
		Field mesh:TMesh
		Field Loc:Vector
		Field Texture:TTexture
				
		Method Create:Int(numZombies:Int)
			If Not list Then list = New List<Zombie>
			For Local xiter:Int = 0 Until numZombies
				Local z:Zombie = New Zombie
				z.mesh = LoadAnimMesh("models/zombie.b3d")
				z.Texture = GZombies.ZombieTexture[int(Rnd(0, 4))]
				z.Loc.x = 0'Rnd(0, 1024)
				z.Loc.y = 0
				z.Loc.z = 20'Rnd(0, 1024)
				z.mesh.ScaleMesh(5, 5, 5)
				z.mesh.EntityTexture(z.Texture)
				list.AddLast(z)
			Next
			Return 0
		End
		
		Method Update:Int()
			mesh.PositionEntity(Loc.x, Loc.y, Loc.z)
			Return 0
		End
		
End

Class FPSCounter Abstract
	Global fpsCount:Int
	Global startTime:Int
	Global totalFPS:Int

	Function Update:Void()
		If Millisecs() - startTime >= 1000
			totalFPS = fpsCount
			fpsCount = 0
			startTime = Millisecs()
		Else
			fpsCount+=1
		End
	End

	Function Draw:Void(x% = 0, y% = 0, ax# = 0, ay# = 0)
		DrawText("FPS: " + totalFPS, x, y, ax, ay)
	End
End


I'm trying to follow examples but I'm yet able to display anything....


Midimaster(Posted 2013) [#5]
I don't know your way with "SetMojoEmulation()". And I don't know whether it is necessary there, but...

...in my way I need two things more:

To check, whether the textures are really loaded I cancel the Init() as long as the Pre-Loadings has not finished:

	Method Init:Void()		
		If Started Then Return 1

		If Not TPixmap.PreLoadPixmap(["Ground.png","Sky.png"])	
			Return  
		Endif
Print "Preload finished"
....		




And my method needs a "RenderWorld()" in OnRender().

	Method OnRender%()
		Init()
		If Not Started Then Return 0
		RenderWorld()
		Return 0
	End



Amon(Posted 2013) [#6]
Changed it to your recommendation but still get nothing showing.

#If TARGET="win8"
	#WIN8_PRINT_ENABLED=(CONFIG="debug")
	#WIN8_SCREEN_ORIENTATION=15				'bitwise OR of: 1=portrait, 2=landscape, 4=portrait flipped, 8=landscape flipped
	
	#MOJO_AUTO_SUSPEND_ENABLED=False
	#MOJO_IMAGE_FILTERING_ENABLED=True
	
	#TEXT_FILES="*.txt|*.xml|*.json"
	#IMAGE_FILES="*.png|*.jpg"
	#SOUND_FILES="*.wav|*.mp3"
	#MUSIC_FILES="*.wav|*.mp3"
	#BINARY_FILES="*.bin|*.dat|.obj|*.b3d"
#EndIf

#If TARGET="glfw"
	#GLFW_USE_GCC=False
	#GLFW_WINDOW_TITLE="test"
	#GLFW_WINDOW_WIDTH=1024
	#GLFW_WINDOW_HEIGHT=768
	#GLFW_WINDOW_RESIZABLE=false
	#GLFW_WINDOW_FULLSCREEN=false
	#TEXT_FILES="*.txt|*.xml|*.json"
	#IMAGE_FILES="*.png|*.jpg"
	#SOUND_FILES="*.wav|*.mp3"
	#MUSIC_FILES="*.wav|*.mp3"
	#BINARY_FILES="*.bin|*.dat|.obj|*.b3d"
#EndIf

Strict

Import minib3d
Import mojo


Function Main:Int()
	New GZombies()
    Return 0
End
 
Class GZombies Extends App

	Field fpsRate:Int = 30
	Field init_gl:Bool = False
	Global ZombieTexture:TTexture[5]
	
	Field zombie:TMesh
	Field cam:TCamera
	Field light:TLight
	Field Started:Int
	
	
	Method Create:Int()
		SetUpdateRate(fpsRate)
		SetRender()
		
		Return 0
	End
	
	Method Init:Int()
		If Started Then Return 1
		SetFont(LoadImage("mojo_font.png", 96, Image.XPadding))
		If Not PreLoad("models/Zombie_1.jpg, models/Zombie_2.jpg, models/Zombie_3.jpg, models/Zombie_4.jpg, models/Zombie_5.jpg")
			Return False
		Endif

		ZombieTexture[0] = LoadTexture("models/Zombie_1.jpg", 1)
		ZombieTexture[1] = LoadTexture("models/Zombie_2.jpg", 1)
		ZombieTexture[2] = LoadTexture("models/Zombie_3.jpg", 1)
		ZombieTexture[3] = LoadTexture("models/Zombie_4.jpg", 1)
		ZombieTexture[4] = LoadTexture("models/Zombie_5.jpg", 1)
		
		zombie = LoadAnimMesh("models/zombie.b3d")
		
		zombie.PositionEntity(0, 0, -10)
		
		If Zombie.list <> Null
			Local z:Zombie = New Zombie
			z.Create(10)			
		EndIf
		cam = CreateCamera()
		light = CreateLight()
		cam.PositionEntity(0, 4, -10)
		Return 0
	End
	
    
	Method Update:Int()
		
		#If TARGET <> "win8"
			If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then EndApp()
		#EndIf
		
		If Zombie.list <> Null
			For Local z:Zombie = EachIn Zombie.list
				z.Update()
			Next
		EndIf
		
		
		
		
		If KeyHit(KEY_LEFT)
			fpsRate-=5
			SetUpdateRate(fpsRate)
		End
		If KeyHit(KEY_RIGHT)
			fpsRate+=5
			SetUpdateRate(fpsRate)
		End		
		
		Return 0
	End

	Method Render:Int()
		Init()
		If Not Started Then Return 0
		light.LightColor(255, 255, 255)
		light.PositionEntity(0, 30, 0)
		RenderWorld()
		Return 0
	End
End

Class Zombie
		Global list:List<Zombie>
		
		Field mesh:TMesh
		Field Loc:Vector
		Field Texture:TTexture
				
		Method Create:Int(numZombies:Int)
			If Not list Then list = New List<Zombie>
			For Local xiter:Int = 0 Until numZombies
				Local z:Zombie = New Zombie
				z.mesh = LoadAnimMesh("models/zombie.b3d")
				z.Texture = GZombies.ZombieTexture[int(Rnd(0, 4))]
				z.Loc.x = 0'Rnd(0, 1024)
				z.Loc.y = 0
				z.Loc.z = 20'Rnd(0, 1024)
				z.mesh.ScaleMesh(5, 5, 5)
				z.mesh.EntityTexture(z.Texture)
				list.AddLast(z)
			Next
			Return 0
		End
		
		Method Update:Int()
			mesh.PositionEntity(Loc.x, Loc.y, Loc.z)
			Return 0
		End
		
End

Class FPSCounter Abstract
	Global fpsCount:Int
	Global startTime:Int
	Global totalFPS:Int

	Function Update:Void()
		If Millisecs() - startTime >= 1000
			totalFPS = fpsCount
			fpsCount = 0
			startTime = Millisecs()
		Else
			fpsCount+=1
		End
	End

	Function Draw:Void(x% = 0, y% = 0, ax# = 0, ay# = 0)
		DrawText("FPS: " + totalFPS, x, y, ax, ay)
	End
End


I'm wondering if it's the actual .b3d model. Going to try another.....


Midimaster(Posted 2013) [#7]
Do you use the very new minib3d version? Some days ago Adam made some changes in the model loader...

I always pre-test a model on Blitz3D too to confirm the model is correct.


Amon(Posted 2013) [#8]
Yep, using the latest one from the repo. I'm trying to figure out why this is happening to each model I try (.b3d Model ).

I'm about to install the latest version of UUnwrap to see if it will make a difference.


Midimaster(Posted 2013) [#9]
Did you try other targets? What about a test in Blitz3D?

here is a model that works on my system:

https://www.dropbox.com/s/m5pehupdkm2qhob/bug.zip

it should look like this:

http://www.monkeycoder.co.nz/Community/post.php?topic=5016&post=60222


Amon(Posted 2013) [#10]
[edited]

I managed to get it working. Something in my example posted was not sitting well with minib3d but grabbing the simple example posted in the tutorials forum it all seems to be working fine with that.


Amon(Posted 2013) [#11]
Spoke to soon. Everything seems to work fine as long as I remove this:

'		If Not TPixmap.PreLoadPixmap(["Zombie_1.jpg", "Zombie_2.jpg", "Zombie_3.jpg", "Zombie_4.jpg", "Zombie_5.jpg"])
'			Return  
'		Endif


???


Midimaster(Posted 2013) [#12]
As I understood, you wrote, that you were able to see your model now. Why do you want to remove this lines?

There is still no "model chapter" in the tutorial, but it will come. What source code do you mean?

Also my "tutorial model" had big problems and finally caused an update of minib3d. In the minib3d thread there is already a minimal source code for models and adams offers one in the minib3d module samples. Maybe you found another bug.

All this experiences shall flow into my next chapter of minib3d tutorial. So I'm very interested in all those problems.


Amon(Posted 2013) [#13]
Hi Midimaster,

I am still unable to see my model or the model you linked to. Basically whenever I use the Preload in my last post all I get is just a black screen when the app executes.

Removing the preloading seems to work but still cannot see the models. I know it works because I set the cameracls color to red. So when I see a red screen I know everything has initiated properly to some extent.

If I don't see the red screen and just a black screen I know something has gone wrong and removing the preload of the textures seems to fix it.

This is all strange. Oh, in the test example I use now I cannot even see visible a cube created with createcube. Just the red screen.


Midimaster(Posted 2013) [#14]
What about the code sample of the first of my tutorial chapters (a cube)? Copy exactly the code without changing anything and try it on HTML5 on Windows on Firefox.


Perhaps destroy the build folders


some sentences about bug reports:

Please add the target, os, browser, versions, etc... in each post here when you report a bug.

As long as I have not published the model chapter, I cannot really help in this case. At the moment I feel responsable only for techniques I already offered in the tutorial. If you are able to start one of these tutorial codes (exactly the same without changes) and it does not work, I would investigate the reason.

did you already contact adam? He is responsable for all trechniques not offered in the tutorial. Models are still "unsafe" and there are a lot of untested possibilities. It is helpful if you can point to a new bug. But you have to ensure, that all tutorial codes are running already perfect on your device. This ensures, that you did not found a unknown fundamental bug.

I would say that not preloading the textures cancels the complete model and so the camera starts working. But this point only the error of missing textures, nothing more....

At the moment we believe in pre-loading works perfect. So the bug seems to come from the model loader. the app crashs.. the screen is black

Test the pre-loading with a second app. Pre-load one texture and connect it to a cube or a sprite. Report the result


AdamRedwoods(Posted 2013) [#15]
i've corrected your code to work on GLFW.
the biggest problem was using Update() instead of OnUpdate() and Render instead of OnRender(). Also, miniB3D does not work for the Win8/WinPhone8 target set yet. (I broke Rone's version since the MojoEmulation was put in, working on fixing it).