Return default loaded texture (OpenB3D)

BlitzMax Forums/MiniB3D Module/Return default loaded texture (OpenB3D)

Hezkore(Posted 2016) [#1]
Does anyone know if there's a way to return the default texture used by a loaded mesh?
Let's say I've made a mesh of a dumpster and that the texture it uses is "dumpster_texture.png".
When I've loaded my dumpster into OpenB3D I want to somehow get that "dumpster_texture.png" filename.
I've tried stuff like Mesh.GetSurface(1).brush.name[0] and Mesh.GetSurface(1).brush.tex[0].file
But only get blank results.


RustyKristi(Posted 2016) [#2]
Haven't tried, is it supposed to be a similar command like in B3D?


Hezkore(Posted 2016) [#3]
I haven't tried with B3D, so I have no idea.


RustyKristi(Posted 2016) [#4]
Not sure if this is exactly what you're looking for but probably this one:

http://www.blitzbasic.com/b3ddocs/command.php?name=GetBrushTexture

To find out the name of the texture, use TextureName$

http://www.blitzbasic.com/b3ddocs/command.php?name=TextureName

OpenB3D Equivalent:

GetBrushTexture
https://github.com/markcwm/openb3d.mod/blob/master/openb3d.mod/inc/TBrush.bmx#L87
TextureName
https://github.com/markcwm/openb3d.mod/blob/master/openb3d.mod/inc/TTexture.bmx#L267


Kryzon(Posted 2016) [#5]
How do you know it's on surface 1? How do you know that that surface has a valid brush, instead of the default blank brush?

You have to dig through all the surfaces (and their respective brushes) of the mesh.
If you still can't find it then you're querying the wrong mesh.


Hezkore(Posted 2016) [#6]
@Kryzon
Because I made the mesh myself and I know it's only got one surface, and since GetSurface(0) is always blank it means 1 will be the first surface in the mesh.
Oh and accessing 0 or 2 spits out "Attempt to access field or method of Null object" anyways.
So for this test mesh I'm sure it's surface 1 I want. :)

@RustyKristi
Nice find!
TextureName() does work with textures I've loaded myself.
But I can't get it to work with a texture loaded by a mesh.
For example
TextureName(GetBrushTexture(GetSurfaceBrush(GetSurface(Mesh, 1))))
doesn't seem to work...
Nor does the more direct way
TextureName(Mesh.GetSurface(1).brush.tex[0])
They always just return a blank string.

Oh and just to be sure.
I also tested this
For Local i:Int = 1 To CountSurfaces(mesh)
	Print TextureName(GetBrushTexture(GetSurfaceBrush(GetSurface(Mesh, i))))
Next
But only blank strings are returned.


RustyKristi(Posted 2016) [#7]
Good start! Maybe you can check with minib3d or B3D if what you're looking for is indeed supported.


Hezkore(Posted 2016) [#8]
For now I'm just going to assume that all meshes use one texture and that the filename is the same as the mesh's filename but as a PNG.
It's a bad way of doing it, but I need to move forward.
If anyone finds a way of doing it, please give me a heads up.
And thanks for all the help.


Kryzon(Posted 2016) [#9]
Send the model to my e-mail and I'll try here.


Hezkore(Posted 2016) [#10]
It's literally just a quad with a smiley face on.
Here you go anyways: https://dl.dropboxusercontent.com/u/2842751/plane.zip


Kryzon(Posted 2016) [#11]
Hi. I haven't downloaded it yet, but please try this first.
myTexture:TTexture	= GetBrushTexture( GetSurfaceBrush( GetSurface( Mesh, 1 ) ) ) )

file:String		= String.FromCString( TextureString_( TTexture.GetInstance( myTexture ), TEXTURE_file ) )
file_abs:String		= String.FromCString( TextureString_( TTexture.GetInstance( myTexture ), TEXTURE_file_abs ) )

Print file
Print file_abs



Hezkore(Posted 2016) [#12]
It prints two empty strings.
Infact it works just like the tests above.
It works with an actual Texture I load myself, but not with textures from a mesh.
I'm guessing OpenB3D forgets to set those fields when loading a mesh.