Skip to main content

Set light for own shape.

8 replies [Last post]
blabloeblabloebla
Offline
Joined: 2010-04-10

I've created a Shape3D but it doesn't show shining light on it.
I've created that shape with a QuadArray but now I don't know how to set the light on it, I can't do generateNormals or someting like that.
At the branchGroup is set a ambientLight and a directional light.

Now it's look like: http://i33.tinypic.com/2li77g5.png

Does someone know how I can set the shiny light on it?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
blabloeblabloebla
Offline
Joined: 2010-04-10

I know, that works by by sun's maked shapes, like Sphere, Box...

But for my own shape I need to do some special first like "Generate normals", "Set Normals" or someting like that.

But I don't know how I can set the normals.
And without normals there is no shine on the shape.

ralphld
Offline
Joined: 2010-08-02

Each vertex of the normal array points in the direction that you want the light to be reflected.
1,0,0 reflect in X direction
0,1,0 reflect in Y direction
0,0,1 reflect in Z direction

from: http://minitraff.cvs.sourceforge.net/viewvc/minitraff/Testing/DHUD3D.jav...
I tried to post the code and couldn't. just look for "dnorm".

The finished program is at:
http://minitraff.sourceforge.net/

HTH
Ralph

blabloeblabloebla
Offline
Joined: 2010-04-10

I couldn't use the "dnorm" because I have a QuatArray and that's a TriangleArray.

And I don't know how I can set the normals by myself.
because I have only 8 points that used 24 times, point 0, 1, 2, 3, 4, 5, 6 and 7 are all of them a hook that used by X, Y and Z, do I now set 1,1,1 as normals for each point as normal?

Message was edited by: blabloeblabloebla

aces
Offline
Joined: 2003-07-17

Just wondering why you didn't use NormalGenerator ...

From GeometryInfo Javadocs:

[code]
GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
// initialize the geometry info here
// generate normals
NormalGenerator ng = new NormalGenerator();
ng.generateNormals(gi);
// stripify
Stripifier st = new Stripifier();
st.stripify(gi);
GeometryArray result = gi.getGeometryArray();
[/code]

There is a complete example from Daniel Selman's book here :
http://www.javafaq.nu/java-example-code-790.html

blabloeblabloebla
Offline
Joined: 2010-04-10

oh, thank you!

I use a QuadArray, and i've read on the internet how to set normals with a normalgenerator for a QuadArray, but I thought it didn't work.

But there was a bug in te code, I returned te wrong object :P

blabloeblabloebla
Offline
Joined: 2010-04-10

Now I've the same problem with textures, how can I set/generate texture coords?
Does someone know that?

lyfox
Offline
Joined: 2010-08-17

Sure, try surfing this one.
http://java.sun.com/developer/onlineTraining/java3d/
Chapter 7 is what you need.

Good luck.

ralphld
Offline
Joined: 2010-08-02

The specularColor in material is what creates highlights. What does your material look like?

Material(javax.vecmath.Color3f ambientColor,
javax.vecmath.Color3f emissiveColor,
javax.vecmath.Color3f diffuseColor,
javax.vecmath.Color3f specularColor,
float shininess)

Ralph