EntityTexture command not working?

Blitz3D Forums/Blitz3D Beginners Area/EntityTexture command not working?

StOrM3(Posted 2004) [#1]
I have a cube b3d file I have loaded in, then I get a random number between 0,4 and loadtexture the correct cube0 - cube4 texture based on that, then do an entitytexture(hold(ID_cube)\item,hold(ID_cube)\texture) and it is not working, it will not apply the new textures.. Do I have to acquire a surface first or something or am I missing something about the entitytexture command, I have tried it with both the blitz3d built in createcube() command and with a loaded mesh...

I am at a loss, help if you can.. thanks you guys.

Ken


eBusiness(Posted 2004) [#2]
This time I think I understood the problem, after what you have done the entity is still untextured. But it's pretty hard for me too to figure why, maybe someone else is smarter, but I'll need some code to stand a chance.


StOrM3(Posted 2004) [#3]
If counter = 20 Then
  hold(counter)\item = loadmesh("../media/cube.b3d")
  hold(counter)\item1 = CopyMesh(hold(counter)\item)
  hold(counter)\anim1 = 0
  hold(counter)\ID = counter
  hold(counter)\points = 0
  hold(counter)\sizex# = 2
  hold(counter)\sizez# = 2
  hold(counter)\gridx = -1
  hold(counter)\gridz = -1
  hold(counter)\status = 1
  hold(counter)\itemcount = 1
  hold(counter)\lives = 0
  hold(counter)\puzzle = 0
  hold(counter)\secret = 0
  hold(counter)\time = 0
  hold(counter)\sphere = 0
  hold(counter)\fruit = 0
  hold(counter)\cube = 1
  hold(counter)\particle = 0
  hold(counter)\player = 0
  hold(counter)\texture = 0
  hold(counter)\nextitem = ID_cube
  hold(counter)\nextarray = 20
  HideEntity(hold(counter)\item)
  HideEntity(hold(counter)\item1)
  counter = counter + 1
EndIf

If grid(countx%,countz%) = ID_cube Then ;wall section so create a cube and load a texture for it.

		  lvlgrid(countx%,countz%)\item1 = hold(ID_cube)\item1

		  ;rndynum = Rnd(1,2)

		  ScaleEntity(lvlgrid(countx%,countz%)\item1,1.1,1.1,1.1)

		  rndtnum = Rnd(0,9)  ; get a rnd num 0-9, to select a texture to load and assign to wall.
		  tfilename$ = "../media/cube" + Str(rndtnum) + ".png" ;used to load in randomized textures.
            tfilename$ = Trim$(tfilename)
		  lvlgrid(countx%,countz%)\texture = LoadTexture(tfilename$)
            Text 250,600, "Texture:" + tfilename$    
		  EntityTexture(lvlgrid(countx%,countz%)\item1, lvlgrid(countx%,countz%)\texture)
		  
		  lvlgrid(countx%,countz%)\item = CopyMesh(lvlgrid(countx%,countz%)\item1)
		  lvlgrid(countx%,countz%)\anim1 = 0
		  lvlgrid(countx%,countz%)\cube = 1  ;this is a wall section, so texture is needed also.
		  lvlgrid(countx%,countz%)\nextitem = ID_cube  ;we will always be a cube, never changing.
		  lvlgrid(countx%,countz%)\nextarray = ID_cube ; array position of cube item loaded.
		  lvlgrid(countx%,countz%)\sizex# = 2.0
		  lvlgrid(countx%,countz%)\sizez# = 2.0
		  lvlgrid(countx%,countz%)\gridx = countx%
		  lvlgrid(countx%,countz%)\gridz = countz%
            PositionEntity lvlgrid(countx%,countz%)\item,countx% * GX#, 0, countz% * GZ#
		  EntityType lvlgrid(countx%,countz%)\item, GetEntityType(hold(ID_cube)\item)
            EntityRadius lvlgrid(countx%,countz%)\item, 2.0,2.0
		  lvlgrid(countx%,countz%)\status = 1 ; the wall segment is always stopped.
		End If


Hope this helps.. I am just doing like other examples, loading the mesh, then copying the mesh, then using loadtexture, and then entitytexture... and I get nothing, but original texture.


eBusiness(Posted 2004) [#4]
Ok, that was a bit more complicated than I had hoped, try setting up only the required parts of the function you think don't work. I am really just guessing, not much into texturing meshes, but I don't think anyone would have found the bug based on your first post. If it doesn't help, then I hope somebody can figure something that I can't :P


Gabriel(Posted 2004) [#5]
To save me reading your code unless I really have to, let's start with the obvious. Is the cube UV mapped?


Ross C(Posted 2004) [#6]
rndtnum = Rnd(0,9)  ; get a rnd num 0-9, to select a texture to load and assign to wall.


You said above that you get a random texture between 0 and 4. Also, when dealing with integer random numbers, try and use

Rand

instead of

Rnd


StOrM3(Posted 2004) [#7]
okay, the code changes I made at home, are from 0-4, this is from code base at work which is basically the same with only minor changes, and yes the cube is UV mapped, I have already created the cube in milkshape, and textured it, and then exported it to a b3d file called cube.b3d which is shown in the above code that it is loaded. Also, it does load and display the wall cubes correctly using the texture inside the model I originally exported, what is not working is applying the texture to the entity, and yes I know it has the texture named correctly and yes it appears to be loading the texture, but for some reason when using entitytexture it is not getting applied. I have checked the texturename using text yada yada inside the main loop to see that the textures well at least the last one are getting loaded tfilename$ prints the fullpath and texturename perfectly on the screen, and Blitz3D visual blitz with debug on, does not give me any errors about missing texture or anything like that, I was getting that before I changed the texture names, on the png files. Could it be possible that when I exported the png files from imageforge and it wanted to use the papercolor as transparency info, that it made the texture in essence blank ? Then I thought about this, and opened image forge re-opened each texture and did a save as on each one to resave them as cube*.tga the * being the number from 0-4. Then I changed the code to load the tga files and tried applying that texture to the model, and got the same results, no change in texture whatsoever, merely would use the one in the model.

I then realized that possibly since the png file already had the alpha set, when i converted them to tga files that it also set the alpha channel in the tga to be the same thing that was in the png files, so I have not had a chance to first resave the files as bmp to strip out the alpha info, then load those and re-save as tga files.. but I don't really think this is the issue, I think there is something I am missing either a flag or something when loading the texture or do I need to use updatenormals on the model before doing entitytexture, or do I need to select a specific surface in the model and apply the texture to that, then do the same for each surface in the model ?

I am unsure, all I know is I get the same results, whether I use a createcube() or a loadmesh("../media/cube.b3d") and try to entitytexture(whatevermodel it is)

Now keep in mind I have a cel-shading routine I made from the code archives that I pass all the models into, which should not affect the cubes though, since I filter those out and only cel-shade the items, not the wall cubes ID=ID_cube, or 20 for hold(20)\item or hold(20)\item1 refer to the same model as I use copymesh to create the item from item1 after texturing it.

There is nothing real complicated in the code above.. Just wanted you to see that I was just loading the mesh, assigning it to a type field, and loading the texture assigning it to a type field also, then applying that texture to that mesh.

Please help... ;') BTW: I am at work, or I could give you exact code segments.. but this is very close to working code at home, very little difference, I left out the rest of the loadmodels function, as it is not needed to understand the cube and texture portion. The above code is from two separate functions, one called LoadModels, the other CreateGrid. The CreateGrid just loops through to for loops from 0-9, and if the lvlgrid(countx,countz)\ID = ID_cube then it does the random texturing etc.. if it is not just processes the other items differently, cel-shading them etc..

Hope this helps, but I think I got way more in depth in this explanation then should be necessary for it to work.


StOrM3(Posted 2004) [#8]
so no suggestions.. hmmm... not the reply I was looking forward too.

Oh well when I get home, I will hack around on it, until I see if I can get it to put one texture on it, then go from there.

Thanks for the help.


_PJ_(Posted 2004) [#9]
Are you sure the .b3d has all the corredct UV information?
I had a .B3D mesh that had lost some of this data, and would not show any textures.


StOrM3(Posted 2004) [#10]
I would almost believe that except for the fact that I also tried using createcube() and it would not texture either.


Matty(Posted 2004) [#11]
in your code before EntityTexture command put this line:
if lvlgrid(countx%,countz%)\texture=0 then RunTimeError("Texture does not exist") 

IF you get the runtime error you know that the texture does not exist most likely because you have specified an invalid path when loading it.