Apply a texture to one object of the mesh

Started by
13 comments, last by vecchia 13 years ago
Hi all,
I have a mesh that contains 9 objects, I would like to texture the object that the user clicks. I alredy have the code that manage the mouse click of the user but I don't understand how could I apply the texture. Can someone help me?
Advertisement
It's not clear what you mean by "object." Do you mean, perhaps, that you have an object with 9 meshes?

If so, can you select one of the meshes with your mouse pick?

Also, are the texture coordinates setup for each mesh and you just want to apply a texture to that mesh, or are you trying to apply texture coordinates to the area of the mesh where you click the mouse?

What API are you using? OpenGL? DirectX?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I'm using DirectX 9, I'm loading a single .x file that contains 9 spheres and I draw them. I would be able to click with the mouse on one of them and draw a texture that texturize the ball
Are the 9 spheres separate meshes, or are they all part of a single mesh? That is, do you have 9 LPD3DXMESH objects or just a single mesh?

If the 9 spheres are all part of a single mesh, it will extremely difficult to single out just a portion of that single mesh as a sphere and assign a texture to just that portion. You'll be better off creating 9 separate meshes ( e.g., with D3DXCreateSphere, or another algorithm ). Alternatively, if you are creating the x-file in an editor, you'll need to create 9 separate x-files so you can load each sphere mesh separately.

Also, as asked above, have the texture coordinates already been created for the spheres? If not, you'll have to assign appropriate texture coordinates to each sphere mesh using an algorithm. If you're creating the spheres in another editor (such as Blender), assign the texture coordinates in the editor, if you can.

Also, as asked above, do you know already know how to pick a mesh with the mouse, or are you asking how to do that? If you need to know how to pick a mesh, take a look at the picking example in the SDK, search here on gamedev for "mouse picking," or google for "DirectX mouse pick."

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

the mesh is only one and I have alredy created the code to pick a mesh with the mouse. I'm usingm blender to create the 3D model and export it to .x format. Basically what I want to do is to load the mesh with predefines texture and change the texture of the picked sphere when the user click on it
As mentioned, it will be extremely difficult to determine what boundaries of the mesh comprise a sphere in one mesh.

Do you render the mesh using something like: for( WORD a=0; a < numMaterials; a++ ) DrawSubset(a)?

If so,then it appears you've assigned a different material/texture to each sphere. The mesh you load should have an attribute table - a table containing a number for each face of the mesh which specifies which subset that face belongs to.

It's still going to be a little difficult, but, once you've picked the mesh and determined which face you've picked, you can look in the attribute table to see which subset the picked face belongs to. Then set the desired texture for that subset when you render it.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Do you render the mesh using something like: for( WORD a=0; a < numMaterials; a++ ) DrawSubset(a)?

yes, I'm using that code

As mentioned, it will be extremely difficult to determine what boundaries of the mesh comprise a sphere in one mesh.

Ok but wouldn't be more difficult to render N spheres? I must rotate the 3D model, so one mesh is simpler to rotate...
You could share the same world matrix for the 9 spheres if you dont want to rotate them on their own. That way they would be moved/rotated like a single mesh.
so anyway it's impossible to apply a new texture to a single sphere on one mesh?

so anyway it's impossible to apply a new texture to a single sphere on one mesh?

From previous post:
once you've picked the mesh and determined which face you've picked, you can look in the attribute table to see which subset the picked face belongs to. Then set the desired texture for that subset when you render it.[/quote]

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement