About Texture

Mar 18, 2010 at 9:15 AM

Those two problems have been solved but an annoying texture problem emerged when I tried to set its Material.

The output scene turns out very strange. I expect the geographic globe picture but the output scene is only attached to picture fragment in a small circle near the bottom. I have implemented all these above in Kit3D and I am sure my vertice, texture and face is correctly set.

Why?How does the texture draw?

It is a little hard to describe it in plain text, it may be a little confusing, how about sending my pictures to your email?

Thanks again!

 

in Page.xmal.cs

private void LoadTexture()
        {
            string uri = "4.jpg";
            var assetLoaderService = KernelContainer.Kernel.Get<IAssetLoaderService>();
            var loader = assetLoaderService.GetLoader<Balder.Core.Imaging.Image>(uri);
            var images = loader.Load(uri);

            if (images.Length == 1)
            {
                Globe.Material.DiffuseMap = images[0];
            }
            
        }

 

in Globe.cs

private void PrepareVertices()
        {
            if (!_isLoaded)
            {
                return;
            }

            GeometryContext.AllocateVertices((Stacks + 1) * (Slices + 1));
            GeometryContext.AllocateTextureCoordinates((Stacks + 1) * (Slices + 1));

            int index = 0;
            for (int stack = 0; stack <= Stacks; stack++)
            {
                float phi = (float)(Math.PI / 2 - stack * Math.PI / Stacks);
                float y = (float)(Radius * Math.Sin(phi));
                float scale = (float)(-Radius * Math.Cos(phi));

                for (int slice = 0; slice <= Slices; slice++)
                {
                    float theta = (float)(slice * 2 * Math.PI / Slices);
                    float x = (float)(scale * Math.Sin(theta));
                    float z = (float)(scale * Math.Cos(theta));

                    GeometryContext.SetVertex(index, new Vertex(x, y, z));
                    GeometryContext.SetTextureCoordinate(index,
                        new TextureCoordinate(slice / Slices, stack / Stacks)
                        );

                    index++;
                }
            }
        }

        private void PrepareFaces()
        {
            if (!_isLoaded)
            {
                return;
            }

            GeometryContext.AllocateFaces(2 * (Slices - 1) * Stacks);

            int index = 0;
            for (int stack = 0; stack < Stacks; stack++)
            {
                for (int slice = 0; slice < Slices; slice++)
                {
                    int n = Slices + 1;

                    if (stack != 0)
                    {
                        GeometryContext.SetFace(index,
                            generateFace(
                                (stack + 0) * n + slice,
                                (stack + 1) * n + slice,
                                (stack + 0) * n + slice + 1
                            ));
                        index++;
                    }
                    if (stack != Stacks - 1)
                    {
                        GeometryContext.SetFace(index,
                            generateFace(
                                (stack + 0) * n + slice + 1,
                                (stack + 1) * n + slice,
                                (stack + 1) * n + slice + 1
                            ));
                        index++;
                    }
                }
            }

            GeometryHelper.CalculateVertexNormals(GeometryContext);
        }

        private Face generateFace(int a, int b, int c)
        {
            Face f = new Face(a,b,c);
            f.DiffuseA = a;
            f.DiffuseB = b;
            f.DiffuseC = c;

            return f;          
        }

Coordinator
Mar 18, 2010 at 10:03 AM

Pictures would be great, my email : einar _at_ dolittle _dot_ com

 

Mar 23, 2010 at 12:23 PM

Im not sure this will help, but i had several probs setting materials, and i've found that pictures must be sized to a power of 2, like 16,32,256 etc...

And preferencially in png format 32-bit...

Coordinator
Mar 23, 2010 at 4:41 PM

PNG should be limited to what is supported by Silverlight - I'd love reports if that is not the case.

16 bit per channel is not supported for instance by Silverlight, so that won't work. 

Also, Khalla is correct, power of 2 sized textures (Width & Height independently). In the latest version of the code you'll get an exception if that is not the case.