View Full Version : Texture in .X files
Pooja Agarwal
04-21-2006, 04:44 AM
I am using DirectX 9.I have referred the Tutorial:6 Using Meshes... in the tutorial i have a .x file (tiger.x) which displays a tiger with a texture in tiger.bmp.... when i tried to change the .x file to some other file supposed cube.x (present in the sdk) then it shows me a cube but the texture is not present(it appears black). when i debugged i saw that the texture filename it gets ie. cube.bmp and also the loading of the texture does not fail but then the cube appears black... also when i tried to load the same tiger.x file and manually changed the texture filename to cube.bmp then the tiger appears with the texture in cube.bmp... my requirement is to display cube.x with a texture cube.bmp... Any help will be appreciated ... thanks
CobraLionz
04-21-2006, 06:47 AM
I've had similar oddities with that cube.x file before. My suggestion is to make your own cube and use the DX exporter to edit the file if it is text.
The easiest way to confirm is to use the meshviewer in the sdk.
Does the cube have any (valid) texture coordinates?
Pooja Agarwal
04-23-2006, 10:15 PM
Actually my problem is not the cube... i need to load a non geometric object and then add a texture to it .. the shape i want to load is the alphabet 'R' ... i have a .X file which has a shape 'R' in it but i dont know how to view the .X file so as to check if contains the texture coordinates or no .. the same R.x file is used in a code which uses DirectX 5 and then texture is added to it by creating wrap to the mesh and then adding the texture to the mesh and it works ... i want to use the same R.x file and add texture to it using DirectX 9 but DrectX 9 does not support 'wrap' so i want to find an alternate way ... i cant draw that 'R' shape using coordinates as it will be very complex to get the curves and all.... so want to know
1) how to load a .x file and then add a external texture to it in DirectX 9
2) or how to edit the .x file so that texture can be added to it
3) and also how to view the contents of .X file
4) how to create a new .x file from an existing .x file
1. You set a texture for your 3d device then this texture is used during the render pass. Hence you can load any texture you want and use it for your x-file instead of using the one texture specified within the x-file. However within an x-file you can only specify one texture for each mesh witch is an unfortunate limitation. If your mesh should include e.g. a bump map then you have to load it separately. So you would need some texture management of your own.
2. Each x-file contains all the data needed to render the mesh on screen. If you do not need a texture you probably have no texture coordinates stored in your x-file. Therefore you will not be able to apply a random texture in a sensefull way. You would need to add texture coordinates witch you probably won’t be doing by hand.
3. Use a modelling program to look at it. E.g. Cinema4D, Maya, Blender or something like it. Using directX you should also have a model viewer in case you don’t have a modelling program. Alternatively you can look at the x-file in a text editor. Then you are unlikely to guess the shape of the mesh but you should see if there are texture coordinates supplied. (You should be able to see the FVF used in the x-file)
4. Load the old x-file in a modelling program then modify it and save it again as the new x-file.
Pooja Agarwal
04-24-2006, 11:53 PM
Thanks moe for the help ... i understand what you are saying but it is not helping me.. cause my problem is that the R.x file is loaded using
D3DXLoadMeshFromX() API and also i get the name of the texture file R.bmp from the R.x file.. also the texture was loaded using the
D3DXCreateTextureFromFile() API but then it was not displaying the texture on the object and the object appeared black... this is happening because the R.x file does not contain the texture coordinates .... i tried to automatically generate the texture coordinates and now it is working ... i set the Texturestagestate to the following whcih is displaying the texture
SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX,
D3DTSS_TCI_CAMERASPACEPOSITION | 1 );
But i want to know :
1) Is there a way by which i can generate the texture cordinates of a non geometric figure like what i have an alphabet 'R'... because for non geometric objects there are no equations.. so is it possible to get the texture coordinates for a irregular shape present in a .X file???
2) As in the tutorial we have Tiger.x file which contains the texture coordinates .. so i want to know how those texture coordinates have been found for a tiger ..
Thanks to all for helping me with this
Ragards
Pooja
In general:
If I understand you correctly you are taking about texture mapping in general. Normally you would use a modelling program to set the texture coordinates exactly the way you like. By that I mean you would apply some uv texture mapping. But if you need a more general solution you should think about different ways to map a texture. Like e.g cube mapping, sphere mapping etc.
e.g.
You could apply a texture to a sphere. This gives you some uv texture coordinates for the sphere. In this case you need to compute the texture coordinates by hand and set them as texture coordinates for your mesh. You can do this for any basic shape like sphere, cube, cylinder etc.
If your mesh is irregular (tiger) then you can’t do this anymore. Instead you surround your mesh with a basic shape. You could surround the tiger with a bounding sphere. Then you take a normal for each vertice of your mesh. You intersect the normal with the bounding volume and take the uv coordinate you get from this intersection. Depending on what bounding shape you choose the texture maps more or less suitable.
Instead of taking a normal and intersect it with the bounding shape you could also use other rays. So, that you get more like a projection from the texture along an axis onto your mesh.
You can play with this until you find the way you like to map the texture. Also read up on the topic of texture mapping to get more ideas.
To your questions:
1. If you need exact texture coordinates, you should use a modelling program to apply the texture. This will always give the most exact results. Then the mesh is unwrapped and the triangles are projected onto the texture so they won’t be overlapping and you can paint the texture exactly the way you want it to be.
2. The coordinates were probably found by modelling the tiger in a modelling program. Then the x-file was simply saved as it was modelled.
Hope the idea is clear :)
Pooja Agarwal
04-26-2006, 12:11 AM
Thanks a lot moe for the help ... i will try this one and will let you know if it worked
Pooja Agarwal
04-26-2006, 02:07 AM
i want to know if there is any algorithm or any tool which would calculate the texture coordinates for complex figures in a .X file ... so that the texture coordinates could be added to the .x File and then processed further.....
Any generic algorithm that could be used for complex figures
Any help in this direction will be appreciated
Thanks
Pooja
Any generic algorithm that could be used for complex figures
There is no such thing. I have seen few attempts, but they generally require some sort of user input, like direction and seams.
Pooja Agarwal
04-26-2006, 10:11 PM
So can anyone just tell me the exact way in which i can find the texture coordinates for an irregular figure... i need to know it at the code level .... i am developing this in DirectX 9.0c ... i have managed to get the texture on an irregular figure by setting the texture stage to the following for automatic coordinates calculation
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX,
D3DTSS_TCI_CAMERASPACEPOSITION | 1 );
but i want to find the texture coordinates of the irregular figure and then get the texture on the figure..
In one of the posts moe suggests the use of modelling program for the same but i am unable to figure out that how to go abt it....
link of any example or tutorial which finds the texture coordinates of an irregular figure is what i need...
Thanks to everyone for the help that they are providing me
Pooja
Reedbeta
04-26-2006, 11:48 PM
Are you asking about how to create the texture coordinates for a model, or how to extract them from a model file that already has them? It sounds like the first, where as geon explained there is no general algorithm. Think about what you're asking for - you want to squash a mesh of pretty much arbitrary topology onto a 2D rectangle. It's pretty much impossible (today) for a computer to figure out how to do this in a sane way; it has to be an artist decision. Although there has been some interesting work with octree textures lately.
Pooja Agarwal
04-27-2006, 02:30 AM
Yes .. i had a irregular figure in a .X file but there were no texture coordinates in the .X file.... hence to add texture to the figure i needed the texture coordinates ...... well i found out a tool which takes as input a .X file containing any figure without texture coordinates and it outputs a .X file which contains the texture coordinates for the figure ....
The tool is "UVAtlas.exe" which is present in samples in DirectX 9.0c SDK
Anyways thanx to everyone for the help...........
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.