Jump to content
  • Advertisement
Sign in to follow this  
vecchia

Apply a texture to one object of the mesh

This topic is 2649 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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."

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!