[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

sphere mesh texture map using MDX

Posted on 2006-07-09
8
Medium Priority
?
2,100 Views
Last Modified: 2013-12-08
hello,

how can i wrap a given texture to my sphere mesh in direct x? i tried
using the code in the 'Applying Textures part 3 (ZMan)' article (
http://msdn.microsoft.com/coding4fun/zman/zmantextures3/default.aspx )
but it didnt work.

can you please show me some code and make it as brief and simple as
possible?

when i use the following code:

device.SetTexture(0, TextureLoader.FromFile(device,
System.Windows.Forms.Application.StartupPath + @"\woodcrate.bmp" ));

it makes the sphere black in color. i dont see the texture clearly on
the mesh. i just see a black sphere. do i need to set texture
coordinates?

thanks for your time,

Zahid
0
Comment
Question by:zahidayar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 4

Expert Comment

by:joachimc
ID: 17081305
I am guessing you haven't set any lights pointing at the sphere.

You could try making the texture self iluminating to test if that is the problem. It's one of the material settings I just can't remeber at the moment. Could be the emissive property.

But of course you need to set the ambient lighting and some kind of directional light to get it right.
0
 
LVL 3

Accepted Solution

by:
OutsideTheBox earned 1500 total points
ID: 17108390
Zahid,

Could you please post your code, there could be a number of things that could cause this problem. It would help us to eliminate possibilities.

Are you sure you have woodcrate.bmp in the correct folder?

Most of the time you create a mesh with textures in a program like 3ds max or maya and these programs set texture coords and you do not have to set them manually because they import with the mesh. It doesn't look like that is your case but I would think in your case they just defaulted to 0,0 at vertex #1 of your sphere and you would have seen 'something' anyways. So I don't think that not setting them is your problem.

You said that you can't see the texture clearly. Can you see it at all? Is it there but somehow incorrect? or is the sphere simply just black with the texture missing?

I have found when following tutorials, that when they do not work, I've made a small, simple mistake in the coding somewhere that just takes a while to find, then I thump my forhead and wonder why I missed it. It rarely is the tutorial.

Steve
0
 

Author Comment

by:zahidayar
ID: 17111107
thanks for the replies....
lighting is set up...the sphere mesh just looks completely black....i didnt notice anything of the texture...i also asked this question on another forum (gamedev.net) and they suggested that i should setup the VertexFormat (and the texture coordinates) of the mesh properly...i will work on that soon hopefully...im working on other things right now...thanks again for the replies...

Zahid
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:zahidayar
ID: 17111110
by the way, i meant black with light shining off of it.. :)
0
 

Author Comment

by:zahidayar
ID: 17204470
hello,

this is my code:

            protected void SetupMaterial()
            {
                  this.iconMaterial = new Material();      
                  this.iconMaterial.Diffuse = Color.Blue;
                  this.iconMaterial.Specular = Color.LightGray;
                  this.iconMaterial.SpecularSharpness = 15.0F;
                  this.iconDrawingDevice.Material = this.iconMaterial;
                  this.iconDrawingDevice.RenderState.SpecularEnable = true;
                   this.iconDrawingDevice.SamplerState[0].AddressU = TextureAddress.Wrap;
                          this.iconDrawingDevice.SamplerState[0].AddressV = TextureAddress.Wrap;
           
if ( (addNelementIconMesh.VertexFormat & VertexFormats.Texture1) == 0 )
{
    // create a cloned mesh with texture coordinates attached to it
    Mesh tempMesh = addNelementIconMesh.Clone ( this.addNelementIconMesh.Options.Value , this.addNelementIconMesh.VertexFormat | VertexFormats.Texture1 , this.iconDrawingDevice );
    // get rid of the old mesh
    this.addNelementIconMesh.Dispose();
    // assign the new one
    this.addNelementIconMesh = tempMesh;
    // calculate them
   // CalculateSphereTextureCoordinates();

}

            this.iconDrawingDevice.SetTexture(0, TextureLoader.FromFile(this.iconDrawingDevice, System.Windows.Forms.Application.StartupPath + @"\woodcrate.bmp" ));
            }

as u can see the CalculateSphereTextureCoordinates() method is commented... i got some parts of the code from a member at gamedev.net....i would be happy if someone would provide a possible implementation of the CalculateSphereTextureCoordinates() method...

thanks for your time,

Zahid
0
 

Author Comment

by:zahidayar
ID: 17204473
yeah...woodcrate.bmp is in the correct folder...they are both in the same folder
0
 

Author Comment

by:zahidayar
ID: 17302905
hello,

yeah Steve, i set the texture coordinates and the texture mapping worked. :)

i used the following code:

            private void CalculateTextureCoordinatesForThisSphereMesh ( Mesh sphereMesh )
            {
                  using ( VertexBuffer vb = sphereMesh.VertexBuffer )
                      {
                          CustomVertex.PositionNormalTextured[] verts = (CustomVertex.PositionNormalTextured[])vb.Lock(0, typeof(CustomVertex.PositionNormalTextured), LockFlags.None, sphereMesh.NumberVertices);                          
                             try
                              {
                                  for (int i = 0; i < verts.Length; i++)
                                  {
                                            verts[i].Tu =  Convert.ToSingle ( Math.Asin( verts[i].Nx ) / Math.PI + 0.5 );
                                            verts[i].Tv = -1 * Convert.ToSingle ( Math.Asin( verts[i].Ny ) / Math.PI + 0.5 );                  
                                  }
                              }
                              finally
                              {
                                  vb.Unlock();
                              }
                    }
            }

thanks for the help everyone..

Zahid
0
 
LVL 3

Expert Comment

by:OutsideTheBox
ID: 17317811
Glad you figured it out.

Thanks,
Steve
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question