texture a model

Blitz3D Forums/Blitz3D Programming/texture a model

Rook Zimbabwe(Posted 2004) [#1]
OK I have a model of a playing card. It has two meshes labeled FRONT and BACK. In UU3D I labeled the textures FRNT and BAK as well... Back has a texture assigned to it. Front is blank.

I then made an animated type texture called spades... guess which suite that is!

How do I apply the animated texture to the mesh labeled front as attach it as the MAT labeled FRNT???

-RZ


Rook Zimbabwe(Posted 2004) [#2]
Maybe no one knows how???


big10p(Posted 2004) [#3]
You can assign a texture to a brush with BrushTexture and then apply it to a specific surface with PaintSurface. Is that what you want?


Rook Zimbabwe(Posted 2004) [#4]
Yeah... I think so... I couldn't find that in the language refernce... Do you tink brushtecture will work with animated textures??? Or would I have to define my pictures further???


_PJ_(Posted 2004) [#5]

BrushTexture brush,texture[,frame][,index]



The Frame flag sets the animation frame - so, yes it works for animated textures.


Rook Zimbabwe(Posted 2004) [#6]
So what am I dong wrong???

; JUST to see if the card thing works... RWD
Graphics3D 800,600,32,1
SetBuffer BackBuffer()

player=CreatePivot()
camera=CreateCamera(player)
;setup lighting
light=CreateLight()
RotateEntity light,45,45,0
AmbientLight 48,48,48    ; was 32,32,32
CameraRange camera,.1,9999
PositionEntity player,0,250,0

; player eyes height: 1.7m and hit radius out there
EntityRadius player,.15
EntityRadius camera,1
TranslateEntity camera,0,200,0

EntityType camera,1

card=LoadMesh("card.b3d") ; card b3d is a mesh with two faces FRONT and BACK labeled

texture=LoadAnimTexture("spades0.png",1,349,349,1,13) ; this texture exists and is in proper dir

cface=CreateBrush() ; example in b3d shows this is necessary

BrushTexture cface,texture,1,1 ; this is where the program halts!!!!!!!!!!!!!!!!!!!!!!!!!

PaintMesh FRONT,face ; since it halts above I don't know if this works!

While Not KeyHit(1)


  mxs#=MouseXSpeed()/4
  mys#=MouseYSpeed()/4
  xa#=(xa#-mxs#)Mod 360
  ya#=(ya#+mys#)Mod 360  
    
  MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
  RotateEntity camera,ya#,xa#,0
    

If KeyDown( 205 )=True Then TurnEntity camera,0,-.5,0
If KeyDown( 203 )=True Then TurnEntity camera,0,.5,0
If KeyDown( 208 )=True Then MoveEntity camera,0,0,-.5
If KeyDown( 200 )=True Then MoveEntity camera,0,0,.5


x#=EntityX(camera)
y#=EntityY(camera)
z#=EntityZ(camera)

PositionEntity camera,x#,y#,z#

  UpdateWorld()
  RenderWorld()
  
  Flip
Wend
End
I don't know... just wanted to look at the card front and back so I put it in the 3D flyby framework... Program insists texture doesn't exist!
Texture file is: 349 X 3109
It's me isn't it... :(


Afrohorse(Posted 2004) [#7]
Woo there, that's a big texture! Probably too big for your graphics card to hold therefore it cant load it. So, having an entire suite in one texture is a bad idea.

What would be better is to have each card as a seperate texture - I assume you're not going to be showing all 52 cards at once so this way you'll only have to use the card textures that are currently in the game.

Also, most 3D cards only accept power of 2 sized textures (blitz would scale them for you when it loads it in, if its not) - so in this case, your 349x3109 would probably be scaled up to 512x4096, which is HUGE!

So, best you're best off making seperate textures for each card and make them 128x256 in size, load them all in at the start and as you create each card to display, assign the correct texture.

In the code you gave, you're first loading in a card, then calling PaintMesh on 'FRONT' even though FRONT doesn't exist, you can't label something in a mesh and paint it, not in blitz.

If you want to paint the front and back two different textures, then you can either build up a mesh in code with two surfaces and paint each surface, or load in two meshes and paint each mesh differently.

Personally, I'd build up a card mesh in code - its only 2 surfaces, each made up of 2 triangles.


Afrohorse(Posted 2004) [#8]
Just read the other older thread about this - Using the .png or any other compression format won't help you, at the end of the day when you load the texture in it will uncompressed to 16 or 32 bit. So after scaling, and converting to 32-bit, this one texture will be 8Mb - Plus another 2.7Mb for mipmaps. So for all four suites, thats a grand total of - ~42.8Mb! (Thats not counting any meshes, or any other graphics in your scene)

Also, holding all the cards (or just one suite) in one texture won't help you either, unless your planning on showing all possible cards at once, because although it may save you on swapping textures when rendering, it will still upload the suite entire texture to the video card it would very slow if the graphics card couldn't hold all the textures in memory.

If you were to have a single texture per card, when it came to rendering it would only have to upload a bunch of smaller textures and only the ones it needed - therefore, much more likely to fit into graphics memory and more friendly to the texture cache.

As for making up a card of component parts, its really not worth the effort, and jokers, j,q,k would still need special texture parts. All that extra work, for parhaps a few less texture swaps for which you wouldn't even notice the difference in framerate - it's not like your rendering 1000's of cards at once (are you?!)

You can easily save out 52 images, at 128x256 8-bit palettized all that only comes up to about 1.6Mb on disk, which is nothing in the grand scheme of things. Then when all are loaded in and coverted to 32-bit, that would be 6.5Mb (8.67Mb with mips) held in normal RAM. Then when you want to render it and you had say, 10 different cards currently displayed in your game, that would only take up at most 1.25Mb of video ram (big difference from 33Mb!)

In a lot of cases, using a bigger texture made up of smaller textures works very well to speed up rendering and reducing texture swaps, but in this case - it's not.


Rook Zimbabwe(Posted 2004) [#9]
Quite possibly it is too big... I have 256mb on the AGP but let me shrink the image.

Would the fact that the image is too big give me an "TEXTURE DOES NOT EXIST" error???


Afrohorse(Posted 2004) [#10]
If it can't load it - it won't exist.

There is a texture size limit on the graphics card it doesn't matter how much memory it has, and it varies from card to card. Although, I'm not sure if blitz3D either rescales it, or just doesn't load it.

There are many reasons why a texture won't load, file doesn't exist, texture too big, invalid format - parhaps even the load anim texture has a limit on the number of frames you can specify. Try loading in an image you know works, then keep increasing the size and number of frames until it breaks - then you'll know exactly what th elimits are.


Rook Zimbabwe(Posted 2004) [#11]
Thanks... Yeah I missed the logic *if it CAN'T load it it won't exisy* I suppose I was thinking of file checking... I am gonna scale it down by half and save one and then by half again and save one and see if those work,,,

-RZ


Rook Zimbabwe(Posted 2004) [#12]
OK reduced the size and madeit 128X1024 seems to like that... BUT

Can't paint surface. Surface name is FRONT. Surface MAT name is FRNT Do I have to tell B3D to get surface names first??? how???


Rook Zimbabwe(Posted 2004) [#13]
Figgered it out (maybe) but I still cant see the results of my works... Program no longer halts though!
Well if someone wants the stuff I would gladly email it to them!
-RZ


_PJ_(Posted 2004) [#14]
Hmm You've positioned the camera, but not the objects, so the objects would be placed at 0,0,0 by default which is beneath the camera (Y axis).

Perhaps altering camera pitch (TurnEntity +/-90,0,0 - I think)
or using PointEntity. Then you should see the results.


Rook Zimbabwe(Posted 2004) [#15]
Yeah... I realized that and felt like an idiot! I revamped the code and now all works... I am going to add pointentity to simplify looking at the card but it has both a front and a back.

Query: How to better have a looking.. how to have a better looking front. Front is kind of fuzzy. I think the animated image is as high as I can get it with my current setup. Changed the image to 64 X 512 and though the file is only 30k in size it wont go any larger... thats a JPG. PNG is larger but thats without compression. Trying compression now.
-RZ


Afrohorse(Posted 2004) [#16]
As I said before, don't use an animated texture - use a different texture per card. Then you can have bigger textures and they won't look fuzzy.