Change texture on model
BlitzMax Forums/MiniB3D Module/Change texture on model
| ||
Hi, Is it possible to load a model that use 2 textures and then change one of them during runtime? I'm going to create the model in Milkshape, and want to change one of the textures while loading the game. If it's possible, what command would I need to use to do this? I haven't used Blitz3D, and I didn't understand much of the commands. I think I should use some of the brush functions, right? Thankful for any help/code examples. |
| ||
Correct, brushes are the way to replace textures during runtime. |
| ||
I found PaintMesh, and it takes 2 arguments. One brush and one mesh. But how do I replace only one of the textures on the mesh with the brush? As a simple example, I want to load a mesh that looks like a picture frame. One texture is the nice golden frame, the other one is a placeholder inside the frame. Then when the game starts, I want to change the placeholder with a new texture, keeping the golden frame. As far as I can see, the PaintMesh function would replace both textures. Edit: After some more digging around in the online B3d manual, I found the PaintSurface function. Is there a way to find the surface of a mesh using groupnames from the milkshape files? |
| ||
A group within milkshape will result in its own mesh, not a surface. A surface is a texture on a mesh, so if you have 2 textures on a mesh (multi texturing), this would result in 2 surfaces. And you are meant to replace both textures. The main point is that you replace the texture on layer 0 with itself again but the texture on layer 1 with a null texture (1x1 black masked for example. perhaps MiniB3D supports the usage of 0 / null there unlike Blitz3D) |
| ||
Tried this. Got a black screen when I added the PaintMesh function.SuperStrict Import sidesign.minib3d Graphics3D 640,480,0 Local mesh:Tmesh = LoadMesh("model.b3d") Local cam:Tcamera = CreateCamera() PositionEntity cam, 0,10,-30 ' Load the wanted textures ' This one is already used in the mesh, and we want to keep it: Local keepimg:TTexture = LoadTexture("tex1.png") ' This is the one we want to change the placeholder texture to: Local replaceimg:TTexture = LoadTexture("tex3.png") ' Create new brush and replace texture Local brush:TBrush = CreateBrush() BrushTexture brush, keepimg, 0,0 BrushTexture brush, replaceimg, 0,1 ' Paint the mesh PaintMesh( mesh, brush ) While Not KeyHit( KEY_ESCAPE ) UpdateWorld RenderWorld Flip Cls Wend Where did I do what wrong? :) Edit: To clarify: The model.b3d file contains 4 triangles. They are grouped two and two into two groups, and each group have one material. (Using the milkshape terms) Edit 2: Here's a ZIP with the textures, the bmax file and the model in both B3D and Milkshape format. http://www.mediafire.com/?8ywy5dbz3z7 |
| ||
SuperStrict Import sidesign.minib3d Graphics3D 640,480,0 Local mesh:Tmesh = LoadMesh("model.b3d") Local cam:Tcamera = CreateCamera() PositionEntity cam, 0,10,-30 ' Load the wanted textures ' This one is already used in the mesh, and we want to keep it: Local keepimg:TTexture = LoadTexture("tex1.png") ' This is the one we want to change the placeholder texture to: Local replaceimg:TTexture = LoadTexture("tex3.png") ' Create new brush and replace texture Local brush1:TBrush = CreateBrush() BrushTexture brush1, keepimg, 0,0 Local brush2:TBrush = CreateBrush() BrushTexture brush2, replaceimg, 0,1 While Not KeyHit( KEY_ESCAPE ) If KeyHit(KEY_SPACE) Then PaintSurface( mesh.GetSurface(1), brush1 ) PaintSurface( mesh.GetSurface(2), brush2 ) EndIf UpdateWorld RenderWorld Flip Cls Wend You have to use 2 brushes because your model has 2 surfaces. Each surface has to be painted seperately. |
| ||
Ah, so that's how it works? Works just great, thanks! :) Last question. Can I somehow find the surface I want to retexture automatically? I was unable to find any function that returns the texture filename or material name. What I did find was that the surface index numbers seems to match the group order in milkshape. Can I trust this, or will it end with a big trial and error when I start to create bigger and more advanced models? |