Jump to content

  • Log In with Google      Sign In   
  • Create Account

Doubt with textures


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Roberto Vbr   Members   -  Reputation: 115

Like
0Likes
Like

Posted 10 April 2014 - 05:06 PM

Hello to all. I had begun to study the directx, but had to stop because of work. Have learned how to load a 3D model (FBX) and I get how to load a model with a simple texture. My problem is that I can not find an example that clearly tell me how to load a model with multiple textures. Example: I have a model of a house that has four rooms, each room has a texture to the walls on the inside and one for outside walls. How to put the textures correctly? I thought about using a material for each room, but return to the same problem on how to get a certain texture in the right index and right vertices. 
 
I appreciate any hint or answer to make me understand how to correctly assign multiple textures.


Sponsor:

#2 Yourself   Crossbones+   -  Reputation: 1133

Like
2Likes
Like

Posted 10 April 2014 - 11:45 PM

Typically you would use submeshes. so a model (aka mesh), is actually an array of models ( frequently called submeshes).

a mesh is split into submeshes based on various strategies: artist defined, based on material/shader/texture/..., gameplay related reasons, ...

Do note that this (and pretty mutch any asset related operations), should be done offline.



#3 Tom KQT   Members   -  Reputation: 1588

Like
2Likes
Like

Posted 11 April 2014 - 01:29 AM

 ( frequently called submeshes).

Or subsets. You'll encounter the term subset in the DirectX documentation (D3DXMesh), not submesh.

 

How to create the mesh (room) with different materials - this depends on your modeling software (Blender, Maya, 3ds max etc.).

 

Then in DirectX it works generally like this:

When you load the mesh, you go through all subsets and create a material for each of them. Each such a material has its colors and lighting properties (diffuse, ambient, emissive, specular color and power...), textures (diffuse map, specular map, normal map, lightmap...) and effect (shaders, rendering style in general).

When you then want to render the mesh, you must render every subset separately. In fact you'll realise that it is not so different from having separate meshes instead. But of course you have just one model file and don't have to do the export from the modeling software many times.

 

The D3DXMesh interface implements all this for you and it quite good for beginners, but I don't know whether you use it or not, you didn't say what version of Direct3D are you using.


Edited by Tom KQT, 11 April 2014 - 01:30 AM.


#4 Roberto Vbr   Members   -  Reputation: 115

Like
0Likes
Like

Posted 11 April 2014 - 02:27 PM

Thank Yourself and Tom KQT the information. The version of directx that I am using is 11.0 (I'm programming with the intention that users of Windows 7 and Windows 8 can play for free). On this issue of subsets I'll search to see more using the FBX SDK how to go all subsets, I confess that I still do not idea how to do that yet. To create the models I'm using Blender version 2.70, I've seen the hierarchy system and really the model that created the house only has a mesh (created at home doing extrude from plane) covering materials that may become even more easy.



#5 Anonymous Noob   Members   -  Reputation: 123

Like
2Likes
Like

Posted 11 April 2014 - 05:45 PM

Thank Yourself and Tom KQT the information. The version of directx that I am using is 11.0 (I'm programming with the intention that users of Windows 7 and Windows 8 can play for free). On this issue of subsets I'll search to see more using the FBX SDK how to go all subsets, I confess that I still do not idea how to do that yet. To create the models I'm using Blender version 2.70, I've seen the hierarchy system and really the model that created the house only has a mesh (created at home doing extrude from plane) covering materials that may become even more easy.

 

I've just done this myself for the first time so I'll share my experience.

 

If materials were assigned to the mesh in the 3D program then that information should carry over into the FBX representation. When you're traversing the FBX file you'll find there's a mapping of geometry to material ID. This mapping can be done in different ways so you'll have to examine the FBX sample "ImportScene" to figure out what you need to do to extract that data under different scenarios. Perhaps the best thing to do is run that sample with one of your meshes and pipe its output to a text file. If you do that it's easy enough to track the various bits of output back to the right parts of the sample source and then duplicate that in your own loader/converter.

 

In any case, the point is that the materials set in the 3D program should be mapped to the mesh data by the exporter. For example, if the materials are mapped per polygon then each polygon in the FBX will have a material ID associated with it. Your submeshes, then, should consist of a subset of the polygons per material. If polys 1,2,3,4,5 are material 0 and 6,7,8,9 are material 1, then those are your two submeshes.

 

I create a single index and vertex buffer for the overall model, and the submeshes contain a count of indices, an offset in to the index buffer to start from, and a material ID. Then my draw code goes something like this:

 

SetVertexBuffer( model->vbuffer );

SetIndexBuffer( model->ibuffer );

foreach submesh in model:

     SendMaterialVariablesToConstantBuffer( model->materials[submesh->materialID]->psvariables );

     SendTexturesToPixelShader( model->materials[submesh->materialID]->textures );

     DrawIndexed( submesh->index_count, submesh->index_offset, 0 );

 

Note that this code is obviously representative rather than literal. It's also not the ideal way to set it up for batch-rendering a bunch of the same thing. But it does get the point across, if you just wanted to display the thing in a viewer for example.

 

Now as for extracting the materials from the FBX you'll also find that in the sample. However, you'll also find that the Blender FBX exporter doesn't work properly when it comes to textures. AFAIK the texture it exports is the one set in the UV mapper and not the texture(s) set in the material's properties. That may have changed since I last looked at Blender but it's something to be aware of.

 

In either case you'll have to create a representation of the material information and store that as part of your model data. The exact form that data takes will be entirely up to you.


Edited by Anonymous Noob, 11 April 2014 - 05:57 PM.


#6 Roberto Vbr   Members   -  Reputation: 115

Like
0Likes
Like

Posted 11 April 2014 - 11:25 PM


If polys 1,2,3,4,5 are material 0 and 6,7,8,9 are material 1, then those are your two submeshes.

 

Thanks Anonymous Noob! You gave me a great idea of ​​how to begin creating my loader. Here I was thinking and thinking again and your explanation was easier for me to start.

 

 

 


Now as for extracting the materials from the FBX you'll also find that in the sample. However, you'll also find that the Blender FBX exporter doesn't work properly when it comes to textures. AFAIK the texture it exports is the one set in the UV mapper and not the texture(s) set in the material's properties. That may have changed since I last looked at Blender but it's something to be aware of. 

 

Now I was worried. I will export a model with multiple materials and textures and see the exported file in the blender exporter creates a file in text mode.

Edited: From what I have researched on the problem of blender not export the textures apparently the solution is to use autodesk convert textures and attach the fbx in binary mode and so the textures are part of the model and can be imported with a parser. Now I will try and see if it works.


Edited by Roberto Vbr, 12 April 2014 - 01:16 AM.


#7 Anonymous Noob   Members   -  Reputation: 123

Like
0Likes
Like

Posted 12 April 2014 - 01:19 AM

I just installed Blender 2.7 to check it out and unfortunately it still doesn't export material textures correctly to FBX -- or indeed, at all. Perhaps someone in the Blender community has made an alternate FBX exporter that works correctly.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS