miniB3D - part 3

Monkey Programming Forums/User Modules/miniB3D - part 3

AdamRedwoods(Posted 2012) [#1]
minib3d+monkey
Download:
https://github.com/adamredwoods/minib3d-monkey

Thread continued from:
http://monkeycoder.co.nz/Community/posts.php?topic=2798

Latest update (v0.31):
http://monkeycoder.co.nz/Community/post.php?topic=3211&post=41264


notes:
- current branch: v0.31 requires Monkey V66
- tested on glfw, android, macos, ios, xna

Works!
- normals work
- textures, mipmaps work
- android, works
- vbos and non-vbo fallback works
- sprites
- batch sprites
- context handling for mobile devices
- pick (optimized)
- collisions
- binary load for b3d files (base64)
- animation, bone & vertex
- Load OBJ
- animated textures
- XNA target (courtesy of Rone)
- HTML5 (webGL)
- Shaders
- normal mapping (opengl2.0)


To Do:
- move to quat/matrix internals
- glow shaders, shadows, fast vertex shaders
- MDD/3DS loaders
- terrain





Rone(Posted 2012) [#2]
Hi,

First of all, my English sucks...so if anything is unclear ask, please!

I would like to have a discussion about shader management eg the explosion of permutations...[Vertex lighting alone introduces over a million permutations]

In the case of monkey + minib3d, the integration of X targets and their various interfaces must also be managed: opengl-> glsl, xna/metro -> hlsl and pss -> cg...

With the current interface architecture, you can indeed quickly and easily add new targets, although it is virtually impossible to add new 'features', without any hack to all targets + the minib3d core.

'-----------------------------------------

The first step is an common graphics interface. It could be used to add new effects or enhancing minib3d without having to write target specific MONKEY code.
format_code('
local effect:= XEffect.Load("water")' loads accordant shader for the target
'...
device.SetClipPlane(..)
'...
')
I will implement my xna interface using opengl, for testing purpose...I think that should not be expensive ..

'-----------------------------------------

If an common interface exists, you can add shader, without having to write target-specific monkey code for example, but on real projects its still far too big and hard to handle, because all the permutations of new and existing 'features' must be considered...impossible!

An common solution is a single shader that implements all desired features, and let the application disable the not required features. This can be achieved in various ways:

1. simply ignoring unwantet calculations using shader constants.

2. switching shader features using static flow control.

3. doin it in a preprocess, using #ifndef blocks to enable and disable various parts of the code

Cons:
- all shaders in one big monolithic program
- wastes GPU horsepower
- you will pretty quickly reach the limits. maximum arithmetic calculation, etc..
- difficult to maintain
- error-prone

bad coding practice in the conclusion!

Btw. Thats the way I did it, and Im pretty sure Adam did it the same in glsl.

'-----------------------------------------

An alternative approach is to write many small fragments of shader code, and then concatenate these into various combinations. (needs to be done at compile time since xbox360 and the xna redistrubutable do not contain effect- processors/compilers).

So, I experimented with shader fragments a little and came up with this... specified one fragment per file...for example:
- base.frag
- vertexcolor.frag
- materialcolor.frag
- lighting.frag
- textures.frag
- fog.frag
- ...
format_codebox('
<fragment name="texture$">
<params>
texture texture$;
sampler textureSampler$ = sampler_state { Texture = <texture0>;AddressU = Wrap; AddressV = Wrap; };
</params>
<vs_in>
float4 TexCoord0;
float4 TexCoord1;
</vs_in>
<ps>
float2 coords = textureStages$.coords == 0 ? input.TextureCoordinate0 : input.TextureCoordinate1;
Color *= tex2D(textureSampler$, coords * textureStages$.scale + textureStages$.offset);
</ps>
<vs>
output.TextureCoordinate0 = input.TextureCoordinate0;
output.TextureCoordinate1 = input.TextureCoordinate1;
</vs>
</fragment>

<fragment name="vertexColor">

<vs_in>
float4 Color;
</vs_in>

<vs_out>
float4 Color;
</vs_out>

<vs>
void _main_(_INPUT_ input, inout _OUTPUT_ output)
{
output.Color = input.Color;
}
</vs>

</fragment>
')
An generated fragment, which can be included by the accordant shader permutation, looks as follows:
format_codebox('
struct base_INPUT
{
float4 Position;
float4 Normal;
float4 Color;
float4 TexCoord0;
float4 TexCoord1;
}

struct base_OUTPUT
{
float4 Position;
float4 WorldPos;
}

void base_ps(base_OUTPUT input, inout OUTPUT output)
{
export(float4, Shading, AmbientColor);
}

void base_vs(base_INPUT input, inout base_OUTPUT output)
{
float4 worldPosition = mul(input.Position, world);
float4 viewPosition = mul(worldPosition, view);
output.Position = mul(viewPosition, projection);
output.WorldPos = mul( input.Position, world);
}
')

Shader capatibilities are simple defined by a string for example: "base,lighting,fog", and naturally all needed combinations can be easily pregenerated.

Pros:
- clean code organization
- easy and fast to extend(even if you implement an deferred renderer, the fragments need NO change)
- pretty fast and compact shader code
- new features can be easily added by creating an new fragment ...'refraction.frag', for example.

Cons:
- need to describe a precise interface to each fragment, which makes it hard to plug in 3rd party shader code. In practice it rarely takes more than a few minutes to add the required annotations...*

For me personally, is another relevant point that such a system can be easily extended in order to be truly platform independent:

format_code('
<fragment name="pointlight">
<shader version="3">
<ps>
<dot name="NL" a="WoldNormal,LightDir"/>
<clamp name="lambertTerm" in="NL,0,1" />
<cmp_greater in="lambertTerm,0">
<mul name="shade" in="lambertTerm,LightAttentuationColor"
<Shading in="shade" />
</cmp_greater>
</ps>
</shader>
</fragment>
')

Here' a detailed description of the concept by Shawn Hargreaves:
* http://www.shawnhargreaves.com/hlsl_fragments/hlsl_fragments.html

and some other links:
http://blogs.msdn.com/b/shawnhar/archive/2009/08/17/combining-shaders.aspx
http://preview.library.microsoft.com/en-us/library/ee416565(v=vs.85).aspx

What do you think?


Rone(Posted 2012) [#3]
Here' the update
http://www.load.to/EfTIkw63Da/minib3d_0.2.65.zip

Includes the full featured xna windows/xbox360 sm3 driver

@Rex Rhino:
Maybe you can test it on xbox360?


AdamRedwoods(Posted 2012) [#4]
What do you think?

I agree. Thoughts:

-- how do the end-users (game coders) implement the shader frags? not ideal to compile all variations
-- a common shader language would not be optimized (mobile gfx are not so great at optimization)
-- hardware inconsistencies (Intel IGP/WebGL/Android are picky). this is a trial and error thing

I like shader fragments, this is a good idea and I had thought about this. Right now my shader is one big mess, and terrible on Android. (but i wrote a few others for speed)

A common graphics interface:
Perhaps look at Ogre and Unity to see how they did theirs? I would be open to copying one so we can use their existing shaders. Unity uses a HLSL base and has a translator to convert to GLSL. May be too much for our purposes, and I do like the XML over Cg/script.


Rone(Posted 2012) [#5]

-- how do the end-users (game coders) implement the shader frags? not ideal to compile all variations


If the end user wants to add parallax mapping functionality,for example...the pipeline could looks as follows:

1. Create a new fragment named parralax.frag and save it to /driver/fragments
format_code('
<interface name="ParralaxMapping">
<params>
<param Type="texture" name"NormalMapTex" />
</params>
<ps version="3">
void _main_(_INPUT_ Input, inout _OUTPUT_ output)
{
//...
}
<ps>
</interface>
')
2. Rebuild the fragments.(custom build steps would be great / Of course, only new or modified fragments needs to be build, as well as new permutations needs to be added)

3. Using the parralax functionality with minib3d:
format_code('
Local brush:= CreateBrush()
Local itf:= brush.Interfaces.Find("ParralaxMapping")
If itf Then
Local p:= itf.Parameters.Find("NormalMapTex")
p.SetValue(my_normalmap_tex)
End
' of course, the default TBrush funktionality still works
brush.BrushColor(255,200,100)
')
It is even possible to extend the existing brush, for a simplified interface which takes care for mandatory initialization or updates, for example:
format_code('
Type TBumpMapBrush Extends TBrush

Field _normalMapTexParam:TBrushParameter

Method New()
Local itf:= Interfaces.Find("ParralaxMapping")
If Not itf Then
Print "error: ParralaxMapping interface Not available. Need to rebuild fragments?"
End
EndIf
_normalMapTexParam= itf.Parameters.Find("NormalMapTex")
EndIf

Method SetNormalMapTexture(texture:TTexture)
_normalMapTexParam.SetValue(texture)
End

EndType
')


a common shader language would not be optimized (mobile gfx are not so great at optimization)


yes. Using a hlsl base and translate it to glsl/cg might be better, as you suggested.


AdamRedwoods(Posted 2012) [#6]
Good news everyone!

I have the normal mapping working, so this means I'll polish up everything and get ready for the next release. WHEW! I'M TIRED.


CopperCircle(Posted 2012) [#7]
Great, looking forward to it.


Sammy(Posted 2012) [#8]
Well done Adam! :)


outsider(Posted 2012) [#9]
Hi :)
How can I use collisions? I tried but it does not work:

format_codebox('Strict
Import mojo
Import minib3d
#If TARGET = "glfw" Or TARGET = "xna"
Import os
#End

Global physicstype%=2 'collsion type of physics objects
Global colType%=3 'collision type of static objects

Class CTable
Field pivot:TPivot
Field mesh:TMesh

Method New(cam:TCamera, r#, g#, b#, sx#=5.0, sy#=0.2, sz#=5.0)
pivot = CreatePivot()
cam.EntityParent(pivot)
mesh = CreateCube()
mesh.EntityColor(r, g, b)
mesh.ScaleEntity(sx, sy, sz)
End

Method Update:void()
pivot.TurnEntity(KeyDown(KEY_UP)-KeyDown(KEY_DOWN), KeyDown(KEY_LEFT)-KeyDown(KEY_RIGHT), 0.0)
'pivot.MoveEntity(0.0, KeyDown(KEY_W)-KeyDown(KEY_S)/2.0, 0.0)
End
End

Class MyApp Extends App
Field stol:CTable
Field cam:TCamera
Field light:TLight
Field ball:TMesh

Method OnCreate:int()
Graphics3DInit()
SetUpdateRate 60

cam = CreateCamera()
cam.CameraClsColor(50.0, 150.0, 250.0)
light = CreateLight(1, cam)
'light.RotateEntity(90,0,0)
stol = New CTable(cam, 250.0, 150.0, 50.0)
stol.mesh.EntityType(colType)
cam.PositionEntity(0, 0, -15, True)
ball = CreateSphere()
ball.PositionEntity(0.0, 10.0, 0.0)
ball.EntityColor(255.0, 0.0, 0.0)
ball.EntityType(physicstype)
Collisions(physicstype, colType, 2, 2)
Return(0)
End

Method OnUpdate:Int()
If KeyHit(KEY_ESCAPE)
#If TARGET = "glfw" Or TARGET = "xna"
ExitApp(0)
#end
Endif
ball.TranslateEntity(0.0, -0.1, 0.0)
stol.Update()
UpdateWorld(0)
Return(0)
End

Method OnRender:int()

RenderWorld()
Return(0)
End
End

Function Main:Int()
New MyApp
Return(0)
End')


AdamRedwoods(Posted 2012) [#10]
How can I use collisions? I tried but it does not work:


OnUpdate()
format_code('
If ball.EntityCollided(colType) Then move_y=0; Print "hit"
'' or
If ball.CollisionY() Then Print "hit"
')


outsider(Posted 2012) [#11]
Thanks :)
This means that collisions are different than in blitz3d. sphere does not stop itself when it detects a collision, I have to use something like: If ball.EntityCollided (colType) = 0 Then move_y


AdamRedwoods(Posted 2012) [#12]
This means that collisions are different than in blitz3d.


No. You found a bug! Congratulations!

Line 298 in functions.monkey
format_code('
Function Collisions(src_no,dest_no,method_no,response_no:Int=0)
TCollisionPair.Collisions(src_no,dest_no,method_no,response_no)
End
')


outsider(Posted 2012) [#13]
Ok, thanks, great work :)


outsider(Posted 2012) [#14]
Hi, unfortunately, something is wrong here, BlitzMax's + minib3d collisions are different.

BlitzMax + minib3d:
[bbcode]Import sidesign.minib3d
Graphics3D 640, 480


Type TTable
Field pivot%
Field mesh%

Function Create:TTable(cam:TCamera, r#, g#, b#, sx#=5.0, sy#=0.2, sz#=5.0)
Local t:TTable = New TTable
t.pivot = CreatePivot()
EntityParent(cam, t.pivot)
t.mesh = CreateCube()
EntityColor(t.mesh, r, g, b)
ScaleEntity(t.mesh, sx, sy, sz)
Return t
End function

Method Update()
TurnEntity(pivot, KeyDown(KEY_UP)-KeyDown(KEY_DOWN), KeyDown(KEY_LEFT)-KeyDown(KEY_RIGHT), 0.0)
End Method
EndType

Const physicstype%=2 'B3D Collsion Type of physics objects
Const colType%=3

Global cam% = CreateCamera()
CameraClsColor(cam, 50.0, 150.0, 250.0)
Global stol:TTable = TTable.Create(cam, 250.0, 150.0, 50.0)
Global light% = CreateLight(1, cam)
EntityType(stol.mesh,colType)
PositionEntity(cam, 0, 0, -15, True)

Global ball% = CreateSphere()
PositionEntity(ball, 0.0, 10.0, 0.0)
EntityColor(ball, 255.0, 0.0, 0.0)
EntityType(ball, physicstype)

Collisions(physicstype, colType, 2, 2)

While Not KeyHit(KEY_ESCAPE)
Cls()
TranslateEntity(ball, 0.0, -0.1, 0.0)
stol.Update()
UpdateWorld()
RenderWorld()
Flip()
Wend
End[/bbcode]
result:


Monkey + minib3d:
[monkeycode]Strict
Import mojo
Import minib3d
#If TARGET = "glfw" Or TARGET = "xna"
Import os
#End

Const physicstype%=2 ' B3D Collsion Type of physics objects
const colType%=3 ' collision type of static objects

Class CTable
Field pivot:TPivot
Field mesh:TMesh

Method New(cam:TCamera, r#, g#, b#, sx#=5.0, sy#=0.2, sz#=5.0)
pivot = CreatePivot()
cam.EntityParent(pivot)
mesh = CreateCube()
mesh.EntityColor(r, g, b)
mesh.ScaleEntity(sx, sy, sz)
End

Method Update:void()
pivot.TurnEntity(KeyDown(KEY_UP)-KeyDown(KEY_DOWN), KeyDown(KEY_LEFT)-KeyDown(KEY_RIGHT), 0.0)
End
End

Class MyApp Extends App
Field stol:CTable
Field cam:TCamera
Field light:TLight
Field ball:TMesh

Method OnCreate:int()
Graphics3DInit()
SetUpdateRate 60

Collisions(physicstype, colType, 2, 2)
cam = CreateCamera()
cam.CameraClsColor(50.0, 150.0, 250.0)
light = CreateLight(1, cam)
stol = New CTable(cam, 250.0, 150.0, 50.0)
stol.mesh.EntityType(colType)
cam.PositionEntity(0, 0, -15, True)
ball = CreateSphere()
ball.PositionEntity(0.0, 10.0, 0.0)
ball.EntityColor(255.0, 0.0, 0.0)
ball.EntityType(physicstype)

Return(0)
End

Method OnUpdate:Int()
If KeyHit(KEY_ESCAPE)
#If TARGET = "glfw" Or TARGET = "xna"
ExitApp(0)
#end
Endif
ball.TranslateEntity(0.0, -0.1, 0.0)
stol.Update()
UpdateWorld(0)
Return(0)
End

Method OnRender:int()
RenderWorld()
Return(0)
End
End

Function Main:Int()
New MyApp
Return(0)
End[/monkeycode]
result:



AdamRedwoods(Posted 2012) [#15]
Hi, unfortunately, something is wrong here

yes, in my quest to accelerate collisions (mainly to be usable on android) some things got broken. TPick works, and I thought collisions worked except for sliding, but it appears that it is still wrong.

i've done a little digging and my collision normals in the ray-to-triangle method are coming out wrong, but when i fix them, then tpick ceases to work.

this is a lot of math work to figure out, so unfortunately, it may take me a while.


outsider(Posted 2012) [#16]
Ok, thank you and good luck :) This is a great minib3d port, better than in my dreams.


outsider(Posted 2012) [#17]
Hi,
collisions works when I use ScaleMesh(), RotateMesh() instead of ScaleEntity(), RotateEntity() etc.

[monkeycode]Strict
Import mojo
Import minib3d
#If TARGET = "glfw" Or TARGET = "xna"
Import os
#End

Const physicstype%=2 ' B3D Collsion Type of physics objects
const colType%=3 ' collision type of static objects

Class CTable
Field pivot:TPivot
Field mesh:TMesh

Method New(cam:TCamera, r#, g#, b#, sx#=5.0, sy#=0.2, sz#=5.0)
pivot = CreatePivot()
cam.EntityParent(pivot)
mesh = CreateCube()
mesh.EntityColor(r, g, b)
mesh.ScaleMesh(sx, sy, sz) '<-----HERE
mesh.RotateMesh(10, 10, 10) '<----- added to see effects
End

Method Update:void()
pivot.TurnEntity(KeyDown(KEY_UP)-KeyDown(KEY_DOWN), KeyDown(KEY_LEFT)-KeyDown(KEY_RIGHT), 0.0)
End
End

Class MyApp Extends App
Field stol:CTable
Field cam:TCamera
Field light:TLight
Field ball:TMesh

Method OnCreate:int()
Graphics3DInit()
SetUpdateRate 60

Collisions(physicstype, colType, 2, 2)
cam = CreateCamera()
cam.CameraClsColor(50.0, 150.0, 250.0)
light = CreateLight(1, cam)
stol = New CTable(cam, 250.0, 150.0, 50.0)
stol.mesh.EntityType(colType)
cam.PositionEntity(0, 0, -15, True)
ball = CreateSphere()
ball.PositionEntity(0.0, 10.0, 0.0)
ball.EntityColor(255.0, 0.0, 0.0)
ball.EntityType(physicstype)

Return(0)
End

Method OnUpdate:Int()
If KeyHit(KEY_ESCAPE)
#If TARGET = "glfw" Or TARGET = "xna"
ExitApp(0)
#end
Endif
ball.TranslateEntity(0.0, -0.1, 0.0)
stol.Update()
UpdateWorld(0)
Return(0)
End

Method OnRender:int()
RenderWorld()
Return(0)
End
End

Function Main:Int()
New MyApp
Return(0)
End[/monkeycode]


Amon(Posted 2012) [#18]
I'm getting an error during startup of my game. This is what it shows.



Any ideas as to what is causing it? I can click Abort and continue with my game but after a while it crashes.

[edit]Turns out it was an error with the base64 encoding of the 3d model I'm using. I tried another site http://www.motobit.com/util/base64-decoder-encoder.asp and it works now. :)


Rex Rhino(Posted 2012) [#19]
Hey Rone,

Sorry for replying so late... I haven't had time to check out the website in a while. I will test on the Xbox360 later today!


AdamRedwoods(Posted 2012) [#20]
collisions works when I use ScaleMesh(), RotateMesh()

Great for finding this! I think I may know what the problem is then.

...
Turns out it was an error with the base64 encoding of the 3d model I'm using.

Interesting. I hope the next release will fix some odd problems.

I'm hoping to release it tonight.


AdamRedwoods(Posted 2012) [#21]
!!!!!!!

I've updated minib3d+monkey master on github.
https://github.com/adamredwoods/minib3d-monkey

It is now the latest version that I've been working on. There is still work to be done on it.

New features:
- HTML5
- Xna reach profile
- Opengl 2.0 shaders

Notes:
- for a more robust XNA, you may want to look at Rone's XNA version.
- Shaders are not where I want them to be, but they are functional. I'll have to provide heavy documentation at some point.
- to get Opengl2.0, change the import to read:
format_code('Import minib3d.opengl.opengl20')
- all other targets will auto-import based on target specified.
- see notes v0.30 file
- to use shaders, TShaderGLSL.LoadDefaultShader(vp file, fp file) to change the main shader
- to use a default shader or your own shader, just add TShaderGLSL.LoadDefaultShader(New FastBrightShader)
- the full shader includes Normal Mapping on texture0 (and TextureFX bit 1024)
- writing shaders is not easy business, each target is particular

Notes HTML5 (webGL):
- use TPixmap.PreLoadPixmap([file array]) to preload your textures.

I've been too absorbed with this project, so I'll need to sit back and just do a bug-maintenance mode. I'll try to fix collisions when I have time, but for now I need to refocus on other exciting projects.


bruZard(Posted 2012) [#22]
gl.clearDeptf() is not a function? ;) HTML5 will not work.


CopperCircle(Posted 2012) [#23]
I got the pick collision example to work with HTML5 by commenting out the txt commands, the other examples wont load the models or sprites. Tried to load a test level using GLFW and it seems that parts of the models get scrambled also no textures if I try GLES20.

Thanks for the hard work its getting there.


Rone(Posted 2012) [#24]
Good work!

I will merge this with my latest implementation...It would be great if we can synchronize our work somehow, because otherwise there its a pretty time consuming task...


I've noticed odd slowing factors at around 100 zombies (1 fps) compared to 80 (30 fps) . very strange.


I'm pretty sure that this is caused by the c# DataBuffer implementation used in VertexDataBuffer. Because of the lack of unsafe code support on windows phone, I used System.BitConverter, what seems to be very slow...

When implementing VertexDataBuffer extern using float[] or VERTEX[] it will run at full speed, and also a little faster than the openGL implementation on windows, at least...


+vertex animation copies the buffer, this can be slow, but it may not always be the slowness factor.


Also avoidable, when implementing VertexDataBuffer extern.


bruZard(Posted 2012) [#25]
ok, after update to Monkey V60 i get this error:

Monkey Runtime Error : [Exception... "Not enough arguments" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: http://localhost:65282/main.js :: _glTexImage2D2 :: line 1752" data: no]

C:/Dev/MonkeyPro/modules/minib3d/opengl/opengles20.monkey<1218>
C:/Dev/MonkeyPro/modules/minib3d/ttexture.monkey<123>
C:/Dev/MonkeyPro/modules/minib3d/ttext.monkey<76>
C:/Dev/MonkeyPro/modules/minib3d/examples/pick_collision_test.monkey<65>
C:/Dev/MonkeyPro/modules/minib3d/examples/pick_collision_test.monkey<93>
C:/Dev/MonkeyPro/modules/mojo/app.monkey<57>




AdamRedwoods(Posted 2012) [#26]
If you have Html5 problems, make sure you preload textures or else it won't find the images. I use a different method than Monkey does Since I make sure the pixmap is a power of two and modify it if it isn't.

I'll try to test this version on a fresh install and see of I can't isolate some bugs.

Thanks for testing everyone, it'll get there eventually.


@Rone
Yeah, I notice you use external VertexDataBuffer and was trying to think of a clean way to allow differentiations for this class. I would like to keep implementations in monkey code but perhaps all targets should be extern? I may need to ask Mark for ideas on how monkey can do this without excessive #IF TARGET commands (and same target could have multiple definitions).


Rex Rhino(Posted 2012) [#27]
I am having trouble getting it to run with XNA. I remember there was some instructions for modifying the Monkey source code to get it running... Are those up to date?


Rone(Posted 2012) [#28]
If u are talking about my latest hiDef implementation, I have only tested with v58. Reach is running without changes.

Its not possible to plug in the latest xna driver into the latest miniB3d Version.


src\trans\target.monkey
format_code('
Field FX_FILES$
'...
FX_FILES=Env.Get( "FX_FILES" )
'...
If FX_FILES DATA_FILES+="|"+FX_FILES
')

src\trans\targets\xna.monkey
format_code('
If MatchPath( r,FX_FILES )
cont.Push " <ItemGroup>"
cont.Push " <Compile Include=~q"+t+"~q>"
cont.Push " <Name>"+f+"</Name>"
cont.Push " <CopyToOutputDirectory>Always</CopyToOutputDirectory>"
cont.Push " <Importer>EffectImporter</Importer>"
cont.Push " <Processor>EffectProcessor</Processor>"
cont.Push " </Compile>"
cont.Push " </ItemGroup>"

')
targets\xna\CONFIG
format_code('
- FX_FILES=*.fx
')
Then build and run \src\rebuildall.bmx.


AdamRedwoods(Posted 2012) [#29]
updated, fixed HTML5 problem.

Remember, HTML5 must have textures preloaded (using the included PreloadPixmap command) or it will fail. See FirePaint3d example:
format_code('
TPixmap.PreLoadPixmap(["blitzlogo.png","stars.png","bluspark.png"])
')
will return 1 when finished, so you can create a loop and display an animated loading symbol.


Tested GLFW windows7, works ok.
Opengl11 works on OSX, but gles20 and on iOS simulator, I am having strange install issues, so that will have to wait (can't find OpenGL headers).


Tried to load a test level using GLFW and it seems that parts of the models get scrambled also no textures if I try GLES20.

i may need a test file. is this win or osx?


outsider(Posted 2012) [#30]
Hi, can You try my code? It's works in GLFW and Android, but html5 gave me black screen and:
*glerror: 1282
*tex

I'm using Chrome 21.0.1180.75, Monkey v61b, minib3d v30

[monkeycode]Strict
Import minib3d

Class MyApp Extends App
Field skybox:TMesh
Field cam:TCamera
Field light:TLight

Method OnCreate:Int()
SetRender()
SetUpdateRate(30)
TPixmap.PreLoadPixmap(["niebo.jpg", "niebo_gora.jpg", "niebo_dol.jpg"])
cam = CreateCamera()
cam.PositionEntity(0, 0, -10)
light = CreateLight(1, cam)
#If TARGET="html5"
light.RotateEntity(-180, 0, 0)
#end
skybox = LoadSkyBox()
Return 0
End

Method OnUpdate:Int()
skybox.TurnEntity(1.0, 1.0, 1.0)
UpdateWorld()
Return 0
End

Method OnRender:Int()
RenderWorld()
Return 0
End
End

Function LoadSkyBox:TMesh()
Local m:TMesh = CreateMesh(), s:TSurface, b:TBrush
'front face
b = LoadBrush("niebo.jpg", 49)
s = CreateSurface(m, b)
AddVertex(s, -1, +1, -1, 0, 0)
AddVertex(s, +1, +1, -1, 1, 0)
AddVertex(s, +1, -1, -1, 1, 1)
AddVertex(s, -1, -1, -1, 0, 1)
AddTriangle(s, 0, 1, 2)
AddTriangle(s, 0, 2, 3)
FreeBrush(b)
'Right face
b = LoadBrush("niebo.jpg", 49)
s = CreateSurface(m, b)
AddVertex(s, +1, +1, -1, 0, 0)
AddVertex(s, +1, +1, +1, 1, 0)
AddVertex(s, +1, -1, +1, 1, 1)
AddVertex(s, +1, -1, -1, 0, 1)
AddTriangle(s, 0, 1, 2)
AddTriangle(s, 0, 2, 3)
FreeBrush(b)
'back face
b = LoadBrush("niebo.jpg", 49)
s = CreateSurface(m, b)
AddVertex(s, +1, +1, +1, 0, 0)
AddVertex(s, -1, +1, +1, 1, 0)
AddVertex(s, -1, -1, +1, 1, 1)
AddVertex(s, +1, -1, +1, 0, 1)
AddTriangle(s, 0, 1, 2)
AddTriangle(s, 0, 2, 3 )
FreeBrush(b)
'Left face
b = LoadBrush("niebo.jpg", 49)
s = CreateSurface(m, b)
AddVertex(s, -1, +1, +1, 0, 0)
AddVertex(s, -1, +1, -1, 1, 0)
AddVertex(s, -1, -1, -1, 1, 1)
AddVertex(s, -1, -1, +1, 0, 1)
AddTriangle(s, 0, 1, 2)
AddTriangle(s, 0, 2, 3)
FreeBrush(b)
'top face
b = LoadBrush("niebo_gora.jpg", 49)
s = CreateSurface(m, b)
AddVertex(s, -1, +1, +1, 0, 1)
AddVertex(s, +1, +1, +1, 0, 0)
AddVertex(s, +1, +1, -1, 1, 0)
AddVertex(s, -1, +1, -1, 1, 1)
AddTriangle(s, 0, 1, 2)
AddTriangle(s, 0, 2, 3)
FreeBrush(b)
'bottom face
b = LoadBrush("niebo_dol.jpg", 49)
s = CreateSurface(m, b)
AddVertex(s, -1, -1, -1, 1, 0)
AddVertex(s, +1, -1, -1, 1, 1)
AddVertex(s, +1, -1, +1, 0, 1)
AddVertex(s, -1, -1, +1, 0, 0)
AddTriangle(s, 0, 1, 2)
AddTriangle(s, 0, 2, 3)
FreeBrush(b)

ScaleMesh(m, 40, 40, 40)
FlipMesh(m)
EntityFX(m, 1)
Return m
End

Function Main:Int()
New MyApp
Return 0
End[/monkeycode]
Download


AdamRedwoods(Posted 2012) [#31]
Hi, can You try my code? It's works in GLFW and Android, but html5 gave me black screen


Ok, thanks for this, and I found a few bugs! I will be updating this soon.


Landon(Posted 2012) [#32]
not sure what i am doing wrong i can't get minib3d to run in html5 for the life of me(with preloading textures). do i have the wrong versions?

keep getting glerror 1282

edit:

oh derp you found bugs and are updating..


Rob Pearmain(Posted 2012) [#33]
I am using an Mac.

When I run the "zombie" example iOS, it works fine in the emulator

When I run in HTML5 (Safari) I get

Monkey Runtime Error : TypeError "Null" is not an object, detail here:

format_code('
Monkey Runtime Error : TypeError: 'null' is not an object

/Users/rob/Downloads/MonkeyPro62/modules/minib3d/opengl/opengles20.monkey<94>
/Users/rob/Downloads/MonkeyPro62/modules/minib3d/opengl/opengles20.monkey<904>
/Users/rob/Downloads/MonkeyPro62/modules/minib3d/opengl/opengles20.monkey<50>
/Users/rob/Downloads/MonkeyPro62/modules/minib3d/examples/animation_test.monkey<35>
/Users/rob/Downloads/MonkeyPro62/modules/mojo/app.monkey<53>
')

Looking through the Javasctipt it seems to be related to

format_code('
bb_functions_TurnEntity((this.f_cube),t_turnzx*2.0,0.0,0.0,0);
')

Firefox gives more details
format_code('
Monkey Runtime Error : TypeError: t_ent is null

/Users/rob/Downloads/MonkeyPro62/modules/minib3d/functions.monkey<1330>
/Users/rob/Downloads/MonkeyPro62/modules/minib3d/examples/animation_test.monkey<127>
/Users/rob/Downloads/MonkeyPro62/modules/mojo/app.monkey<57>
')

Looking through the code, and adding alerts, it seems m_Init is never called (Or is called after render which gives this error)

I am using:

iMac
MonkeyPro62
MiniB3D 0.30

Any ideas?


AdamRedwoods(Posted 2012) [#34]

Any ideas?



For the zombie example, the Init() call is in the wrong place. it should be moved from OnRender() to OnUpdate().

Yeah, overall, I rushed to get this update out so there are some things I broke in HTML5. The PreLoadTexture() doesn't work correctly, but is a relatively easy fix for me..... but I'm noticing some drawing problems in the HTML5 pipeline that isn't showing up in other places, so I need to find what is going on.


Rob Pearmain(Posted 2012) [#35]
The work you are doing is awesome Adam, much appreciated.

I made that change, but now seem to get an error on this line

format_code('
bb_opengles20_OpenglES20.prototype.m_GetVersion=function(){
.
.
. err_info="/Users/rob/Downloads/MonkeyPro62/modules/minib3d/opengl/opengles20.monkey<94>";
var t_s=_glGetString(7938);
.
.
.
')

UPDATE: Works on Firefox, not on Chrome or Safari.

Can you post an example of how I would use "TPixmap.PreLoadPixmap" with the Zombie example


AdamRedwoods(Posted 2012) [#36]
Sorry to not reply right away. Here is a short example of preloading, and I've updated the github examples to reflect this as well.

**the key, as I recently found out, is to remember to load the mojo_font.png if I use it when drawing text, as in most of the examples.

Here's a live example. Even works on Safari on an old MacMini (w/o opengl2.0! but only at 3fps)
http://twopisoftware.com/zombietest

[monkeycode]
Class Game Extends App
Field init_gl:Bool = False

Method OnCreate()
SetRender()
SetUpdateRate 30
End

Method Init()

If Not TPixmap.PreLoadPixmap(["Zombie.jpg","mojo_font.png"])
Return
Endif

If init_gl Then Return
init_gl = True

cam = CreateCamera()

zombie[0]=LoadAnimMesh("zombie_b3d_base64.txt")
''.....etc.......
End

Method OnUpdate()

If Not init_gl Then Init(); Return

zombie[0].Animate(1,speed)
''.....etc......
End

Method OnRender()
RenderWorld()
End
End
[/monkeycode]


Sammy(Posted 2012) [#37]
There was a small problem with sliding collisions, have had a chance to look at that Adam?


AdamRedwoods(Posted 2012) [#38]
not yet


Sammy(Posted 2012) [#39]
Ah, no problem then, I wish I had a better understanding of matrix maths to chip in a little.

OT: I look above and Adams reply says "Posted 21 hours ago", while my question says "Posted 1 hour ago". Small forum problem?


Difference(Posted 2012) [#40]
On my mac mini(NVIDIA GeForce 9400), in Chrome and Safari, when trying http://twopisoftware.com/zombietest

I get an alert with :

Monkey Runtime Error : TypeError: Cannot call method 'getParameter' of null

C:/Monkey/modules/minib3d/opengl/opengles20.monkey<96>
C:/Monkey/modules/minib3d/opengl/opengles20.monkey<906>
C:/Monkey/modules/minib3d/opengl/opengles20.monkey<50>
H:/_work/software_dev/_monkey/minib3d_examples/animation_test.monkey<41>
C:/Monkey/modules/mojo/app.monkey<53>

I think I have WebGL enabled in chrome

I get the same error when trying to run it locally.

[EDIT]: It works in Firefox :-)


AdamRedwoods(Posted 2012) [#41]
On my mac mini(NVIDIA GeForce 9400), in Chrome and Safari

Make sure to get the latest and greatest versions of the browser. I think you need OSX10.6 minimum for Safari 5.1+. Also, make sure WebGL is turned on (Preferences->Advanced->Turn on Develop Toolbar->Enable WebGL).

Should work in Chrome 19 on OSX.

The error above (getParameter of null) means the GL context didn't initialize, so no WebGL. At some point I may try to add in a better detector.


Difference(Posted 2012) [#42]
Thanks. It's working in all my browsers now:-:)

In Safari I did what you wrote above.
In Chrome I had to "Deactivate" a flag that "Deactivates WebGL"

For anyone else running into this: Write chrome://flags/ in Chrome's addressbar to get a list of settings and flags to change.

Thanks for a great module!


Rob Pearmain(Posted 2012) [#43]
Hi Adam,

Thanks for all your hard work.

I can confirm (As has "Difference") that it is working on all 3 browsers on my mac (Safari, Firefox and Chrome), and textures are loading fine.

Absolutely excellent

Out of interest, how would I implement Cel Shading like in this example:

Cel Shader

Oh, and you really need to be in the Module Registry as miniB3d is awesome


StoneFaceEXE(Posted 2012) [#44]
Somehow minib3d examples or just my code don't run on my android device. As I start it on the android device it closes with an error "Attempt to access null object"

Do I have to do something before compiling minib3d code? Because html5 runs perfectly.

Android device has 1GHz core, 512RAM, Malli 400 as graphics


AdamRedwoods(Posted 2012) [#45]
i'm getting problems on a few targets, i'll have to check into this. (V62)
you can try to remove the preloader, and just call init() from onCreate().


StoneFaceEXE(Posted 2012) [#46]
Will this help with 2D mojo commands too? Because I can't seem to DrawImage on render if there is RenderWorld() command. It says that you can only use render operation inside OnRender, but I am doing it :)


AdamRedwoods(Posted 2012) [#47]
Will this help with 2D mojo commands too?

For now, no, but a couple targets can. If you need to draw images, load a texture onto a plane. You can use CreateGrid() of 1 and use a second ortho camera using CameraLayer().

In the future I'd like to get mojo working, but also be aware mojo does not work on OpenGL 2.0 so I'd have to wait for that compatibility first.


AdamRedwoods(Posted 2012) [#48]
Will this help with 2D mojo commands too?

For now, no, but a couple targets can. If you need to draw images, load a texture onto a plane. You can use CreateGrid() of 1 and use a second ortho camera using CameraLayer().

In the future I'd like to get mojo working, but also be aware mojo does not work on OpenGL 2.0 so I'd have to wait for that compatibility first.


MikeHart(Posted 2012) [#49]
With the animation example and on my HTC Desire (Android 2.3.3) I get a blue screen, white on white text and a red cube that I can move aroudn somehow with my fingers. The same app shows the zombie in my browser. What did I do wrong?


AdamRedwoods(Posted 2012) [#50]
Yes I've been slacking a little. I think the problem is with the preloader.

EDIT: yes, if I take out the Init() preloader stuff, android seems to work fine.


bruZard(Posted 2012) [#51]
Identifier 'MINIB3D_DRIVER' not found.

How can i fix that?


AdamRedwoods(Posted 2012) [#52]
shouldnt happen, since it is only really used to check between opengl1 and opengl2. what target does it happen on?


Amon(Posted 2012) [#53]
I get it also on html5.

format_code('
C:/Apps/Coding/MonkeyPro65/modules/minib3d/minib3d.monkey<29> : Error : Identifier 'MINIB3D_DRIVER' not found.
Abnormal program termination. Exit code: -1
')


bruZard(Posted 2012) [#54]
this error exists since V65.

so:
format_code('
#rem
#MINIB3D_DRIVER=""

''to choose opengles20, must specify it
#If MINIB3D_DRIVER=""
#if TARGET="glfw" Or TARGET="ios" Or TARGET="android" Or TARGET="mingw"
Import minib3d.opengl.opengles11
#Elseif TARGET="html5"
Import minib3d.opengl.opengles20
#Elseif TARGET="xna"
Import minib3d.xna
#endif
#endif
#end
')

and so...
format_code('Import minib3d.opengl.opengles20')
...animation_test.monkey will compile until

Error : Duplicate identifier 'DataBuffer' found in module 'databuffer' and module 'databuffer'.
Abnormal program termination. Exit code: -1




marksibly(Posted 2012) [#55]
Hi,

I think I have minib3d mostly going now, on glfw anyway.

I'll release a 65b soon, but you can get some of it going by deleting the 'import brl.databuffer' from the top of 'modules/brl/asyncevent.monkey'.

Also, filenames need to have 'monkey://data/' prefixed to them - this is to let monkey know that the file is a 'data/' file, as opposed to a file in the current dir.

The '#If MINIB3D_DRIVER' issue will need a compiler change though, so you'll need to work around that for now. In general, the compiler shouldn't let you reassign config vars like this, but I'm gonna let it slide in the case of vars with 'null' values like this as I can see it's quite useful. I'd prefer to see another way of doing this though...


StoneFaceEXE(Posted 2012) [#56]
It's me again, sorry.
How do you guys make those base64.txt files? I could use that since I can't load any *obj file. Instead of OBJ appears just some cube :(


bruZard(Posted 2012) [#57]
Base64 Encoder: http://www.opinionatedgeek.com/dotnet/tools/base64encode/


Shagwana(Posted 2012) [#58]
Download the above package and tried it in v66, the samples do not seem to be working.

Any idea what needs fixoring to get this working?


StoneFaceEXE(Posted 2012) [#59]
I'm so afraid about Minib3d, it's an incredibly awesome module for monkey and it's sad it is in a such condition :(

Currently it returns...
"Monkey Runtime Error : TypeError: gl is null"
...on html5 target on v66 of Monkey.


AdamRedwoods(Posted 2012) [#60]
I'm swamped this week, but I plan on updating miniB3D. read the above posts, a little tinkering and it will work.
"Monkey Runtime Error : TypeError: gl is null"

gl is null means that gl did not initialize. this is not a problem of minib3d, it means the browser does not like the graphics card or the browser does not support webgl. on some browsers (chrome) you need to turn on webgl support. (post #41)


Xaron(Posted 2012) [#61]
Does 2d mojo stuff already work together with minib3d? :)


StoneFaceEXE(Posted 2012) [#62]
Does 2d mojo stuff already work together with minib3d? :)

Negatory.

For now, no, but a couple targets can. If you need to draw images, load a texture onto a plane. You can use CreateGrid() of 1 and use a second ortho camera using CameraLayer().

In the future I'd like to get mojo working, but also be aware mojo does not work on OpenGL 2.0 so I'd have to wait for that compatibility first.



Xaron(Posted 2012) [#63]
Thanks!


Xaron(Posted 2012) [#64]
Hmm... any hints about minib3d and V66? I can't run any examples nor for GLFW neither for HTML5. WebGL runs fine in my Chrome though.

I did try some tweaks here and there but can't get it working...


AdamRedwoods(Posted 2012) [#65]
working on this now.

p.s. may take a bit of work


Xaron(Posted 2012) [#66]
Thanks Adam, I really appreciate your great work!


Xaron(Posted 2012) [#67]
Is it something complicated? What was the last monkey version minib3d did work with? I will rollback to that version.


StoneFaceEXE(Posted 2012) [#68]
I tried the same.
It seems to work on v63, maybe on v64.
Android (and glfw) refuses to load textures (and examples' ones) but works fine in general. Android also refuses to load any models at all, while trying to access the base64 model app crashes with error, something about INDEX and LIMIT with various numbers (though INDEX always equals LIMIT), depending on how big model is.


AdamRedwoods(Posted 2012) [#69]
V62 was the last version I was using for a while.

If textures are not loading in the examples, get rid of the PreLoader() function and init_gl checks.

Re: Android crash for models: I think the model is limited to 65535 vertices, since I am using short integers for vertices index (16-bit). Also keep in mind that file filters may need to be turned on for base64 files to be copied in the data folder.

But I might add I tested V62 and the examples worked in Android. If you are having specific model problems, try a different base64 encoder, or if you can, send me the base64 model and I can track down specific errors.


...and finally, the V66 update will require Mark to break the old databuffers (opengl modules point to old databuffers) and change a few bugs in V66, so it will most likely be V66b or V67 that miniB3D will aim for.


Xaron(Posted 2012) [#70]
Thanks for the heads up Adam. I will use V62 then. :)

...or just GLBasic... *gnaaa*


Xaron(Posted 2012) [#71]
For now, no, but a couple targets can. If you need to draw images, load a texture onto a plane. You can use CreateGrid() of 1 and use a second ortho camera using CameraLayer().


Could someone post a small example how to create and use such an orthogonal camera with a CameraLayer? Wouldn't be something like to use a sprite better?


AdamRedwoods(Posted 2012) [#72]
hi, i played with it for a sec but couldn't get my creategrid(1,1) example to work. ugh.

but it works with a sprite, just can't scale the sprite. i'll need to investigate these things later.

format_code('
App Class

''...etc....
Field cam:TCamera, cam2:TCamera

OnCreate()
spr = LoadSprite("Zombie.jpg")


cam2 = CreateCamera()
cam2.PositionEntity(0,0,-1)
cam2.CameraProjMode(2)
cam2.CameraLayer(spr)
cam2.HideEntity()
cam2.CameraClsMode(False,True)

spr.ScaleSprite(0.2,0.2)
End

OnRender()
RenderWorld()
if cam2 Then TRender.render.RenderCamera(cam2)
End
')


Xaron(Posted 2012) [#73]
Awesome, thanks Adam! :)


Xaron(Posted 2012) [#74]
Another question. I use Monkey v62 or v63 (doesn't make a difference).

But creating a simple cube let the GLFW target crash:

format_codebox('

Import minib3d

''note: if your models look weird, config.h depth buffer bits=32

Function Main()
New Game
End

Class Game Extends App

Field cam:TCamera

Field light:TLight
Field cube:TMesh

Field init_gl:Bool = False

Method OnCreate()

SetRender()
SetUpdateRate 30

End

Method Init()

If init_gl Then Return
init_gl = True

cam = CreateCamera()
cam.CameraClsColor(0,0,80)
cam.PositionEntity 0,4,-10

light=CreateLight(1)
light.PositionEntity 0,3,-3

cube=CreateCube()
cube.ScaleEntity(0.5,0.5,0.5)
cube.name = "cube"
PositionEntity cube,-2,2,2

Print "main: init done"
End

Method OnUpdate()

If Not init_gl Then Init(); Return
UpdateWorld()
End

Method OnRender()

RenderWorld()
End
End
')

Any idea? :)

It crashes in line 778 of opengles11.monkey:

format_code('
If vbo

glDrawElements(GL_TRIANGLES,surf.no_tris*3,GL_UNSIGNED_SHORT, 0)

Else
')

I just guess that there's simply no surface so accessing surf.no_tris results in a MAV?


Xaron(Posted 2012) [#75]
Another question:

Using your zombie mesh, why isn't it displayed if I just do

format_code('
zombie = LoadAnimMesh( "zombie_b3d_base64.txt" )
')

It's only displayed if I call CopyEntity...

format_code('
Local tempZ:TMesh = LoadAnimMesh( "zombie_b3d_base64.txt" )
zombie = TMesh(tempZ.CopyEntity())
')

Actually I don't get that...


AdamRedwoods(Posted 2012) [#76]
It crashes in line 778 of opengles11.monkey:

you may need to do an init_gl check in OnRender as well.



It's only displayed if I call CopyEntity...

and it is a persistent field var, not local var? that's strange, it should be added to the display list. I'll need to check that, could be a couple bugs you found, which I thank you for finding.


Xaron(Posted 2012) [#77]
You're welcome. ;)

BTW:

you may need to do an init_gl check in OnRender as well.


That doesn't change anything.

And yes, it is a persistent field so "zombie" is a global variable.


Xaron(Posted 2012) [#78]
Hey Adam, another bug. If I want to load the following mesh I get a crash. The mesh is just a simple plane, nothing special:

http://www.leidel.net/dl/monkey/waterplane.zip

I get a memory access violation in line 118 of monkeyutility.monkey:
format_code('
Return buf.PeekFloat(vid*SIZE+POS_OFFSET + ELEMENT0 )')

Call stack:
.../modules/minib3d/monkeyutility.monkey<118>
.../modules/minib3d/tmesh.monkey<1624>
.../modules/minib3d/tmesh.monkey<1582>
.../modules/minib3d/tmesh.monkey<288>
.../modules/minib3d/functions.monkey<914>


Xaron(Posted 2012) [#79]
Oh and be warned! Actually I use your minib3d module for my current game. There might be tons of requests coming. LOL

Anyway, let me know if I can help, maybe I can fix something here and there. You do a great job, Adam, I can't stress that enough!


Xaron(Posted 2012) [#80]
Another one: Loading OBJ files doesn't work at all. ;)


Xaron(Posted 2012) [#81]
And here we go. Using

format_code('
EntityTexture( mesh, tex, 0, 0 )
')

works, but applying another texture:

format_code('
EntityTexture( mesh, tex2, 0, 1 )
')

leads to a memory access violation.


Xaron(Posted 2012) [#82]
Just tried your examples and I have no textures on my Android phone, no matter if I use v62 or v63b.

I also tried to remove the preload stuff and init_gl check but that didn't help.


AdamRedwoods(Posted 2012) [#83]
ok, i'll have more time this weekend to fix problems, but i'm glad you're putting minib3d through the ringer.

questions:
re: obj, is the obj file being copied over to the debug folder? it may need a file filter in order for trans to copy it over. if it is, then you may be able to turn on the model debug const (in the tmodelobj file) and see where it is stopping. (i want to change those model debuggers to #preprocessor in later updates)


Xaron(Posted 2012) [#84]
Ah well that might be the problem, regarding the obj file. Will check it.

But actually it's not that important, I use b3d anyway.

It's really strange that I see no textures on Android.


Xaron(Posted 2012) [#85]
.


CopperCircle(Posted 2012) [#86]
Looks really good, I must get back to my minib3d zombie game at some point.


CopperCircle(Posted 2012) [#87]
Looks really good, I must get back to my minib3d zombie game at some point.


Xaron(Posted 2012) [#88]
Thanks.

Good news, Minib3d works with Monkey v66 as well. Should have read more carefully what Mark wrote. Just prefix file paths with "monkey://data/" and it works for GLFW.

I still see no textures for Android though...


AdamRedwoods(Posted 2012) [#89]
just a quick fyi-- i have been making great progress on the updates for V66 (and some future proofing). just need to finish testing xna, ios, and fix a couple other things.


Xaron(Posted 2012) [#90]
Awesome Adam! :)


Xaron(Posted 2012) [#91]
Does that mean that you could reproduce these textur issues on Android? :)


AdamRedwoods(Posted 2012) [#92]
Does that mean that you could reproduce these textur issues on Android? :)
no, but i applied the FixPath() right away in the tpixmap loading functions. I'll try to get these changes up this week (pending insane work week)... but if I dont I can just email you a hot fix.

...also your waterplane model did NOT load for me either, its an interesting end-of-file issue so i'm working on handling odd issues with files like that.


Xaron(Posted 2012) [#93]
So textures work for you on Android? Can you send me a working apk please? I just want to check if there's something special with my device.

Oh and please send me any stuff you want to hide_email('martin.leidel@gmail.com')

Thanks so much!


Amon(Posted 2012) [#94]
Can I be emailed the Hotfix, please? I'm eager to see the changes worked on.

Thanks!


AdamRedwoods(Posted 2012) [#95]
ok, i think i've merged my updates to github correctly. if not, let me know. should be the master now.


VERSION 0.31
------------
- updated to work with monkey V66.
- fixed a few bugs
- CameraLayers should work now.
- re-arranged preloading/buffer loading (future-proofing)
- uses #MINIB3D_DEBUG_MODEL = true to debug models instead of hardcoding

- with monkey V66, you can only load new shaders in OnCreate() or OnRender() [android]
- with monkey V66, SetRender() needs to be in OnCreate()


TODO:
-----
- fix collisions
- devise Blender->minib3d plugin

Also, if any OBJ models don't work (and they work elsewhere like in blender), please let me know or send them to me.


Xaron(Posted 2012) [#96]
Thanks Adam, works like a charm now!


outsider(Posted 2012) [#97]
Wow, thanks :)


Amon(Posted 2012) [#98]
Lovely, Thanks!


Amon(Posted 2012) [#99]
Just got the chance to test this and I still get " identifier 'MINIB3D_DRIVER' not found"

Any ideas?


AdamRedwoods(Posted 2012) [#100]
Just got the chance to test this and I still get " identifier 'MINIB3D_DRIVER' not found"

Windows or OSX? Which target? Does this happen with one of the examples?


Xaron(Posted 2012) [#101]
Hi Adam is there a chance to get that 2d text stuff more robust? It's sometimes moving when my camera moves or just disappears. Thanks!


Xaron(Posted 2012) [#102]
I think I've found a bug which was there previously as well.

If I load a mesh using LoadMesh it is displayed.
If I load a mesh using LoadAnimMesh it is NOT displayed until I use CopyMesh.

Looking at the source of tmesh it seems that some magic stuff is happening in LoadMesh which isn't done in LoadAnimMesh?

format_code('
Function LoadMesh:TMesh(file$,parent_ent:TEntity=Null)

Local xmesh:TMesh=LoadAnimMesh(file)
Local mesh:TMesh = CreateMesh()
''
xmesh.HideEntity()
mesh = xmesh.CollapseAnimMesh(mesh)
xmesh.FreeEntity()

mesh.classname="Model"

mesh.AddParent(parent_ent)
'mesh.entity_link = entity_list.EntityListAdd(mesh)

' update matrix
If mesh.parent<>Null
mesh.mat.Overwrite(mesh.parent.mat)
mesh.UpdateMat()
Else
mesh.UpdateMat(True)
Endif

Return TMesh(mesh)

End

Function LoadAnimMesh:TMesh(file$,parent_ent:TEntity=Null)

Local mesh:TMesh
If file.EndsWith(".obj") Or file.EndsWith(".obj.txt")
mesh = TModelObj.LoadMesh(file)
Else
mesh = TModelB3D.LoadAnimB3D(file,parent_ent)
Endif

If Not mesh Then Return TMesh.CreateCube()

Return mesh

End
')


Xaron(Posted 2012) [#103]
And another one:

I have a mesh with a child node which I load with AnimMeshLoad. The child can be found using FindChild (works!). But if I want to rotate that child it doesn't work.


Xaron(Posted 2012) [#104]
Oh well... I worked with you branch but getting the latest "official" v31 I get the following compiler error:

format_code('.../modules/minib3d/opengl/opengles11.monkey<754> : Error : Unable to find overload for ToArray(Float[]).')


Xaron(Posted 2012) [#105]
Alright. Another one. Loading obj files leads to a crash. Adam, just replace the zombie base64 file with this one and try to load the obj file:

http://www.leidel.net/dl/monkey/zombie_obj.zip

I've used Ultimate Unwrap Pro to convert the B3D to OBJ if that makes any difference. It seems that your code expects .txt files for the material while it should load .mtl files?


AdamRedwoods(Posted 2012) [#106]
i'm looking into these errors. i've fixed the "overload for ToArray()"

for .OBJ files, monkey did not seem to like
format_code('
#TEXT_FILES += "|*.obj|*.mtl"
')
so just put a ".obj.txt" and ".mtl.txt" after them.


Xaron(Posted 2012) [#107]
Great thanks! Oh do you mind if I ask what timezone you are? Must be something contrary to mine (GMT+1). LOL


Xaron(Posted 2012) [#108]
Adam, I absolutely appreciate your work on this! You will take a place in the credits of our coming 3d game using Monkey and your lib. :)


AdamRedwoods(Posted 2012) [#109]
Oh do you mind if I ask what timezone you are?

GMT-7

I'm glad someone is using the minib3d library rigorously, i want it to be solid.


Xaron(Posted 2012) [#110]
Oh no problem. You're doing all the hard work while I having fun with it. Well ok not all the time...

Btw, any chance to make that 2d text stuff more beautiful?


Xaron(Posted 2012) [#111]
Hey Adam,

this simple example crashes in GLFW (Windows 7):

format_code('
Import minib3d

Function Main()
New Game
End

Class Game Extends App

Field cam:TCamera

Field light:TLight
Field mesh:TMesh

Field init_gl:Bool = False

Method OnCreate()

SetRender()
SetUpdateRate 30

End

Method Init()

If init_gl Then Return

cam = CreateCamera()
cam.CameraClsColor(80,80,80)
cam.PositionEntity 0,0,-5

mesh = CreateCube()

light=CreateLight()
light.RotateEntity 90,0,0

init_gl = True

Print "main: init done"
End

Method OnUpdate()

If Not init_gl Then Init(); Return

UpdateWorld()

End

Method OnRender()

If Not init_gl Then Return

RenderWorld()

End
End
')


StoneFaceEXE(Posted 2012) [#112]
It seems that blender camera has an effect on minib3d.
Milkshape's converted b3d to txt models without cameras are darker.
Blender's converted b3d to txt models (blender export to b3d and then to txt via B64 encoder) somewhy amplify CreateLight()'s. They are much brighter.
Everything tested on glfw


Also if you delete camera from the scene in blender, export it to b3d, convert to B64 and then try to import it into Minib3d project then it fails. (On GLFW at least)


Also:
PositionEntity by negative ammount (e.g. PositionEntity this,1,5,-15) also crashes GLFW target. MoveEntity works fine.

PointEntity also crashes GLFW for some reason. Maybe it's because of blender models?


AdamRedwoods(Posted 2012) [#113]
Xaron, i tried your simple example on my version (win7) and a fresh install (osx glfw) and it worked. do you have any debugging error codes with it? or is it just a mem exc error?

i'm tracking down the other errors now...


Xaron(Posted 2012) [#114]
Xaron, i tried your simple example on my version (win7) and a fresh install (osx glfw) and it worked. do you have any debugging error codes with it? or is it just a mem exc error?


Adam, now that's interesting. It crashes on my work PC using Windows 7 and OpenGL 3.2 but it works on my home PC using Windows 7 and OpenGL4.0...

Looks like a driver issue.


AdamRedwoods(Posted 2012) [#115]
I have a mesh with a child node which I load with AnimMeshLoad. The child can be found using FindChild (works!). But if I want to rotate that child it doesn't work.


hi, so the reason for this is that the child is probably a bone, right?

If it's a bone, miniB3D cannot currently rotate, move, or scale bones programmatically. This is something that needs to be addressed, so I am doing this now, which means a major change to TBone class.


Xaron(Posted 2012) [#116]
Yes, the child is a bone. Do you have any ETA on this? :)


Xaron(Posted 2012) [#117]
Hi Adam,

another problem. I've made a waterplane and your zombies are up to the knees in the water. Looks good using the GLFW target but horrible on my Android phone. Sometimes I even don't see the waterplane there...

Here's the code (it's your slightly enhanced zombie example)

http://www.leidel.net/dl/monkey/zombietest.zip

THANKS!

BTW: Is there a way to get OpenGLES 2.0 working on the phone?


AdamRedwoods(Posted 2012) [#118]
another problem. I've made a waterplane and your zombies are up to the knees in the water. Looks good using the GLFW target but horrible on my Android phone. Sometimes I even don't see the waterplane there...

very strange indeed. what graphics chip is your android device? mine is doing weird things on a PowerVR530.

EDIT: same problem in opengles20 on android.

problem may be this?
http://stackoverflow.com/questions/8787483/repeated-textures-are-severely-distorted-shaking-when-rotating-camera

EDIT:
In unity too
http://forum.unity3d.com/threads/22267-Jumpy-Textures
solution is to overlap UVs. will see if i can get CreateGrid to do this.


Xaron(Posted 2012) [#119]
Yep, that might be the issue. It's strange, in the emulator it looks okay not on my device. It's a Sony Xperia S with Android 4.0 ICS, so a really capable device...


AdamRedwoods(Posted 2012) [#120]
i did a quick fix on github for the OBJ model loading. should work now.
fixing these other problems this weekend. i fixed the repeating texture problem on android with a CreateGrid() function that allows for disjointed UVs, so yes, the problem is that mobile devices use poor UV precision.

Outstanding issues:
- programmable bone motion
- b3d files not loading properly
- more robust 2d text

anything else?


Xaron(Posted 2012) [#121]
Thanks, yes. Actually LoadAnimMesh looks weird. If I use it to load a mesh it's not displayed until I make a copy mesh.


Xaron(Posted 2012) [#122]
And a MakeNextSuperGameHit function would be nice. ;-)


Xaron(Posted 2012) [#123]
Regarding this more robust 2d text. Can we use different fonts and some scaling then as well? Again Adam, I can't say how thankful I am!!!


Rone(Posted 2012) [#124]
Edit: wrong thread