Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3698592
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:59:59+00:00 2026-05-19T04:59:59+00:00

Been coding for 20+ years. I’m new to Java3d but I am really impressed

  • 0

Been coding for 20+ years. I’m new to Java3d but I am really impressed by it – retained mode is so much easier than direct mode!

Anyway I’m having a problem with lighting. When I create my own geometry I cannot get lighting to work; when I use geometry created by java3d utils (such as Sphere()) the lighting works fine. The issue I’m seeing is that my object is white from all angles. I’ve tried adding ambient and directional lights and my objects are always white.

The docs say I’m not supposed to supply color appearance attributes on my objects if I want to use lighting and I’m not doing that. It also says I should supply normals and I’m doing that. I’ve tried both creating normals by hand and using NormalGenerator. I’ve tried Java3d 1.5.1 and the pre release 1.6.0 without success. I’m using Java 1.6.0_18 on Windows 7 64 bit.

There’s not much to this code. The problem must be something really basic but I can’t see it. I’ve pasted 2 of my geometry creation functions here where the lighting doesn’t work. Please take a look and let me know what I’m doing wrong:

protected BranchGroup createTriangle() {
  Point3f[] vertices = { new Point3f(-1, 0, 0), new Point3f(1, 0, 0),
    new Point3f(0, 1, 0), };
  int indices[] = { 0, 1, 2, };

  GeometryInfo geometryInfo = new GeometryInfo(
    GeometryInfo.TRIANGLE_ARRAY);
  geometryInfo.setCoordinates(vertices);
  geometryInfo.setCoordinateIndices(indices);

 // NormalGenerator normalGenerator = new NormalGenerator();
 // normalGenerator.generateNormals(geometryInfo);

   Vector3f[] normals = { new Vector3f(0.0f, 0.0f, 1.0f), };
   int normalIndices[] = { 0, 0, 0, };
   geometryInfo.setNormals(normals);
   geometryInfo.setNormalIndices(normalIndices);

  Shape3D shape = new Shape3D(geometryInfo.getIndexedGeometryArray());

  BranchGroup group = new BranchGroup();
  group.addChild(shape);

  return group;
 }

 protected BranchGroup createBox() {

  Point3d[] vertices = { new Point3d(-1, 1, -1), new Point3d(1, 1, -1),
    new Point3d(1, 1, 1), new Point3d(-1, 1, 1),
    new Point3d(-1, -1, -1), new Point3d(1, -1, -1),
    new Point3d(1, -1, 1), new Point3d(-1, -1, 1), };

  int[] indices = { 0, 1, 5, 0, 5, 4, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6,
    3, 0, 4, 3, 4, 7, 0, 3, 2, 0, 2, 1, 4, 5, 3, 2, 3, 5, };

  GeometryInfo geometryInfo = new GeometryInfo(
    GeometryInfo.TRIANGLE_ARRAY);
  geometryInfo.setCoordinates(vertices);
  geometryInfo.setCoordinateIndices(indices);

  NormalGenerator normalGenerator = new NormalGenerator();
  normalGenerator.generateNormals(geometryInfo);

  // Vector3f[] normals = { new Vector3f(0, 0, -1), new Vector3f(1, 0, 0),
  // new Vector3f(0, 0, 1), new Vector3f(-1, 0, 0),
  // new Vector3f(0, 1, 0), new Vector3f(0, -1, 0), };
  // int[] normalIndices = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2,
  // 2,
  // 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, };
  // geometryInfo.setNormals(normals);
  // geometryInfo.setNormalIndices(normalIndices);

  Shape3D shape = new Shape3D(geometryInfo.getIndexedGeometryArray());

  BranchGroup group = new BranchGroup();
  group.addChild(shape);

  return group;
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T05:00:00+00:00Added an answer on May 19, 2026 at 5:00 am

    getting shaded lighting to work in Java 3D needs at least normals and a Material node component. You forgot to set an Appearance for your Shape3D instances. So, the default is taken. That results in a not shaded white geometry.

    Add following Appearance to your Shap3Ds’ constructor and they will/should be rendered in red color:

    Appearance appearance = new Appearance();
    Material material = new Material(); 
    material.setDiffuseColor(1.0f, 0.0f, 0.0f);   // red
    material.setSpecularColor(0.2f, 0.2f, 0.2f);  // reduce default values
    appearance.setMaterial(material);
    

    The recommended stable version of Java 3D is 1.5.2 and it can be downloaded here: https://java3d.dev.java.net/binary-builds.html

    August

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been coding in c++ for 3-4 years now, but I'm pretty new to
since last four years i had been coding in c/c++, but those lenthy programs
I've been coding in Ruby for sometime now, but I don't understand when to
Recently I've been doing lots of weekend coding, and have began to really need
I've been coding since my early teenager years. I started out with HTML, went
I've been coding on C++/Linux for 10+ years. I am switching to do Mac
I've been coding websites for a couple of years now, mostly in php and
I've been coding c# for close to 4 years now (vb.net before that) in
I have been coding with MySQL DBs for a couple years now and I
So, I've been coding for a little (2 years), and I have a very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.