Textured Sphere with lighting?

hi

Ich want to make just another space strategy game with xith3d. In order to do so I need to render a solar system. Up to that point it seems quite easy. But I was not able to texture the sphere and lighten it at the same time. How can I do it generally (using the org.xith3d.geometry.Sphere class?

Greetings, Qudus

try something like this:


Sphere s; //your sphere
Material m; //the material with your light settings for e.g. ambient, diffuse light
Texture t; //your texture
// now the texture should be shaded, so you'll have to tell it the material:
m.setColorTarget(m.AMBIENT_AND_DIFFUSE);
//and now apply the material and the texture to your shape
Appearance a = new Appearance();
a.setMaterial(m);
a.setTexture(t);
s.setAppearance(a);

Hi

thank you very much for your quick reply. I found part of my problem but it’s still nor fixed. Hope you can help me further.

This is my code (slightly simplified):

            Transform3D t3d0 = new Transform3D();
            Transform3D t3d = new Transform3D();
            
            t3d.setTranslation(new Vector3f(planet.getDistance(), 0f, 0f));
            TransformGroup tg0 = new TransformGroup(t3d0);
            TransformGroup tg = new TransformGroup(t3d);
            tg0.addChild(tg);
            tg0.setPickable(true);
            tg.setPickable(true);
            
            //sunLight = new DirectionalLight(true, solSys.getSun().getLightColor(), new Vector3f(1.0f, 0.0f, 0.0f));
            sunLight = new DirectionalLight(true, new Color3f(1f, 1f, 1f), new Vector3f(1.0f, 0.0f, 0.0f));
            tg0.addChild(sunLight);
            
            Sphere sph = new Sphere(50, 50, TriangleArray.COLOR_3 | TriangleArray.COORDINATES | TriangleArray.NORMALS | TriangleArray.TEXTURE_COORDINATE_2, planet.getRadius());
            Appearance a = new Appearance();
            
            Texture t = simplyLoadMyCoolTextureAndDoNothingElseWithIt();
            a.setTexture(t);
            
            Material m = new Material();
            m.setEmissiveColor(new Color3f( 1f, 1f, 1f));
            m.setColorTarget(Material.EMISSIVE); // tried it with ambient and diffuse, too
            m.setLightingEnable(true);
            //m.setShininess(50f);
            a.setMaterial(m);
            
            sph.setAppearance(a);
            
            sph.setPickable(true);
            tg.addChild(sph);

Do you know what’s going wrong? I really hope you can help me. I am that colse to goal.

Greetings, Qudus

You set emmisive color to 1,1,1, so it is at its brightest already, the lighting won’t add anything to it, as it reached it max already

try these settings
emmisive 0.0, 0.0, 0.0
ambient 0.25, 0.25, 0.25
diffuse 0.75, 0.75, 0.75

hi

Thank you for yor help. It was the COLOR_3 feature I gave to the Sphere that disturbed my results. Now it works.

I set colorTarget to NONE and used only emissive color at zero. Now it looks the way I wanted it to.

Qudus