> -Polygon winding is important.  That is, polygons can only be seen from
> the 'front', and the front is determined by the direction the points of
> the polygon move in relation to the viewer.  If the points travel in a
> counter clockwise direction, the polygon is facing you; otherwise, you
> are looking at it's back and it will appear transparent.  This can be a
> hard to track down bug.

I borrowed the vertex list from the Box primitive, so hopefully it is
wound properly???

> -Make sure you aren't accidentally rotating your light with your cube model

My light is added to it's own branchgroup and is added only to the top
level branchgroup so there shouldn't be any transforms happening to the
lights.

I just ran a test with the Box primitive and it behaves the same way my
CassattItem3D does, so I'm assuming I have something screwed up with the
lights or appearance (not with the normals) though because box works
properly in my initial prototype.

thanks for the help,

kddubb

>
> Mark McKay
> --
> http://www.kitfox.com
>
>
> Kevin wrote:
>
> >All,
> >
> >I am a newbie working on a fairly simple Java3D application that
> >virtually models networked computer systems.  I have a quick question on
> >surface normals and how they work in the Java3D framework.  But first,
> >here is my (limited) understanding of what surface normals are from the
> >standard Java3D tutorials, etc so you can correct it if necessary.
> >
> >Surface normals to me seem to be analogous to the angle of reflection
> >for shading purposes in the virtual world.  Java3D uses this angle of
> >reflection most (visually) by the specular color and shininess
> >attributes, but should also be used for determining information for
> >diffuse and ambient color.
> >
> >Problem Background:
> >
> >Most of my objects in my environment are boxes of different dimensions.
> >These boxes could be resized at any moment in the application for a
> >multitude of reasons.  Because of this interaction the Box primitive
> >wasn't very conducive and I decided to create my own Shape3D extension
> >that knows how to resize itself in real-time according to my
> >parameters.
> >
> >The Problems:
> >
> >Now when I use CassattItem3D objects, they render mostly correct except
> >that many faces seem partially transparent (I think as a function of
> >their surface normals).  I don't think that was very clear, so I'll
> >state it a different way.  The boxes seem to render the correct
> >specular, diffuse, ambient colors, but the part of the geometry that
> >should be blocked (i.e. the back bottom faces) seem to still affect the
> >shading on the front faces.  The object has an opaque
> >transparency/appearance attribute.
> >
> >I also have these objects as a part of a TransformGroup with a mouse
> >rotator attached so I can view them from different perspectives.  As the
> >objects rotate, faces seem to keep their specular, diffuse, ambient
> >colors.  The light is not in the TransformGroup so it should be
> >independent of the rotation.
> >
> >My questions:
> >
> >1)  Why are the front surfaces appear to be affected by the surface
> >normals of the back surfaces
> >2)  When I rotate the objects, the faces seem to keep their initial
> >specular, diffuse, emissive, and ambient colors even though I am
> >rotating them independently of the light source.  Why don't the colors
> >change in relation to the light source after they are rendered?
> >
> >Anyway, I hope my questions made sense and I didn't show my stupidity
> >too blatantly.  I'm attaching the code with the implementation of the
> >Box so you can correct, flame, etc. about my implementation.  Sorry for
> >the messy code, but it has a day and half of trial and error programming
> >trying to test interactions out.
> >
> >thanks in advance for the help...any pointers to tutorials/FAQs on using
> >surface normals appreciated.
> >
> >kddubb
> >
> >===========================================================================
> >To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> >of the message "signoff JAVA3D-INTEREST".  For general help, send email to
> >[EMAIL PROTECTED] and include in the body of the message "help".
> >
> >
> >------------------------------------------------------------------------
> >
> >/*
> > * Copyright 2004 Cassatt Corporation.  All rights reserved.
> > *
> > * $Id$
> > */
> >
> >
> >package com.cassatt.pt.threedeeviewer.viewer;
> >
> >import com.sun.j3d.utils.geometry.GeometryInfo;
> >import com.sun.j3d.utils.geometry.NormalGenerator;
> >import com.sun.j3d.utils.geometry.Primitive;
> >import java.util.ArrayList;
> >import java.util.Enumeration;
> >import java.util.logging.Level;
> >import java.util.logging.Logger;
> >import javax.media.j3d.Appearance;
> >import javax.media.j3d.ColoringAttributes;
> >import javax.media.j3d.Geometry;
> >import javax.media.j3d.GeometryArray;
> >import javax.media.j3d.IndexedQuadArray;
> >import javax.media.j3d.LineAttributes;
> >import javax.media.j3d.Material;
> >import javax.media.j3d.Node;
> >import javax.media.j3d.PointAttributes;
> >import javax.media.j3d.PolygonAttributes;
> >import javax.media.j3d.RenderingAttributes;
> >import javax.media.j3d.Shape3D;
> >import javax.media.j3d.TransparencyAttributes;
> >import javax.media.j3d.QuadArray;
> >import javax.vecmath.Point3f;
> >import javax.vecmath.Vector3f;
> >
> >/**
> > *
> > *
> > * @author <a href="mailto:[EMAIL PROTECTED]>Kevin Werner</a>
> > * @version $Revision$ $Date$
> > */
> >public class CassattItem3D extends Shape3D {
> >
> >    private static final Logger LOG = Logger.getLogger(
> >        "com.cassatt.pt.thrizzledizzlevizzle.viewer.CassattItem3D");
> >
> >    private static final Point3f[][] CUBE_VERTS = { {
> >        // front face
> >        new Point3f(1.0f, -1.0f,  1.0f),
> >        new Point3f(1.0f,  1.0f,  1.0f),
> >        new Point3f(-1.0f,  1.0f,  1.0f),
> >        new Point3f(-1.0f, -1.0f,  1.0f),
> >    },
> >    {
> >        // back face
> >        new Point3f(-1.0f, -1.0f, -1.0f),
> >        new Point3f(-1.0f,  1.0f, -1.0f),
> >        new Point3f(1.0f,  1.0f, -1.0f),
> >        new Point3f(1.0f, -1.0f, -1.0f),
> >    },
> >    {
> >        // right face
> >        new Point3f(1.0f, -1.0f, -1.0f),
> >        new Point3f(1.0f,  1.0f, -1.0f),
> >        new Point3f(1.0f,  1.0f,  1.0f),
> >        new Point3f(1.0f, -1.0f,  1.0f),
> >    },
> >    {
> >        // left face
> >        new Point3f(-1.0f, -1.0f,  1.0f),
> >        new Point3f(-1.0f,  1.0f,  1.0f),
> >        new Point3f(-1.0f,  1.0f, -1.0f),
> >        new Point3f(-1.0f, -1.0f, -1.0f),
> >    },
> >    {
> >        // top face
> >        new Point3f(1.0f,  1.0f,  1.0f),
> >        new Point3f(1.0f,  1.0f, -1.0f),
> >        new Point3f(-1.0f,  1.0f, -1.0f),
> >        new Point3f(-1.0f,  1.0f,  1.0f),
> >    },
> >    {
> >        // bottom face
> >        new Point3f(-1.0f, -1.0f,  1.0f),
> >        new Point3f(-1.0f, -1.0f, -1.0f),
> >        new Point3f(1.0f, -1.0f, -1.0f),
> >        new Point3f(1.0f, -1.0f,  1.0f),
> >    }};
> >
> >    private static final Point3f[][] PIZZA_VERTS = { {
> >        // front face
> >        new Point3f(1.0f, -1.0f,  1.0f),
> >        new Point3f(1.0f, -0.5f,  1.0f),
> >        new Point3f(-1.0f, -0.5f,  1.0f),
> >        new Point3f(-1.0f, -1.0f,  1.0f),
> >    },
> >    {
> >        // back face
> >        new Point3f(-1.0f, -1.0f, -1.0f),
> >        new Point3f(-1.0f, -0.5f, -1.0f),
> >        new Point3f(1.0f, -0.5f, -1.0f),
> >        new Point3f(1.0f, -1.0f, -1.0f),
> >    },
> >    {
> >        // right face
> >        new Point3f(1.0f, -1.0f, -1.0f),
> >        new Point3f(1.0f, -0.5f, -1.0f),
> >        new Point3f(1.0f, -0.5f,  1.0f),
> >        new Point3f(1.0f, -1.0f,  1.0f),
> >    },
> >    {
> >        // left face
> >        new Point3f(-1.0f, -1.0f,  1.0f),
> >        new Point3f(-1.0f, -0.5f,  1.0f),
> >        new Point3f(-1.0f, -0.5f, -1.0f),
> >        new Point3f(-1.0f, -1.0f, -1.0f),
> >    },
> >    {
> >        // top face
> >        new Point3f(1.0f, -0.5f,  1.0f),
> >        new Point3f(1.0f, -0.5f, -1.0f),
> >        new Point3f(-1.0f, -0.5f, -1.0f),
> >        new Point3f(-1.0f, -0.5f,  1.0f),
> >    },
> >    {
> >        // bottom face
> >        new Point3f(-1.0f, -1.0f,  1.0f),
> >        new Point3f(-1.0f, -1.0f, -1.0f),
> >        new Point3f(1.0f, -1.0f, -1.0f),
> >        new Point3f(1.0f, -1.0f,  1.0f),
> >    } };
> >    private static final int FRONT = 0;
> >    private static final int BACK = 1;
> >    private static final int RIGHT = 2;
> >    private static final int LEFT = 3;
> >    private static final int TOP = 4;
> >    private static final int BOTTOM = 5;
> >
> >  private static final Vector3f[] normals = {
> >    new Vector3f( 0.0f,  0.0f, -1.0f),  // front face
> >    new Vector3f( 0.0f,  0.0f,  1.0f),  // back face
> >    new Vector3f( 1.0f,  0.0f,  0.0f),  // right face
> >    new Vector3f(-1.0f,  0.0f,  0.0f),  // left face
> >    new Vector3f( 0.0f,  1.0f,  0.0f),  // top face
> >    new Vector3f( 0.0f, -1.0f,  0.0f),  // bottom face
> >  };
> >
> >
> >
> >    public static final int CUBE = 1;
> >    public static final int PIZZA = 2;
> >
> >    private double scale;
> >    private int type;
> >    private QuadArray geometry;
> >
> >    /**
> >     * create a Box with defaults
> >     */
> >    public CassattItem3D(double scale, Appearance a, int type) {
> >
> >        geometry = new QuadArray((BOTTOM + 1) * 4, QuadArray.COORDINATES |
> >            QuadArray.NORMALS);
> >
> >        this.setGeometry(geometry);
> >
> >        this.scale = scale;
> >
> >        changeType(type);
> >
> >        //generateNormals();
> >
> >        if (a == null) {
> >            a = new Appearance();
> >            PolygonAttributes pa = new PolygonAttributes();
> >            PointAttributes poa = new PointAttributes();
> >            ColoringAttributes ca = new ColoringAttributes();
> >            LineAttributes la = new LineAttributes();
> >            TransparencyAttributes ta = new TransparencyAttributes();
> >            Material mat = new Material();
> >
> >            //RenderingAttributes ra = new RenderingAttributes();
> >            //ra.setDepthBufferEnable(true);
> >            //a.setRenderingAttributes(ra);
> >
> >
> >            poa.setPointSize(5.0f);
> >            poa.setPointAntialiasingEnable(true);
> >            a.setPointAttributes(poa);
> >
> >            la.setLineWidth(1.0f);
> >            la.setLinePattern(LineAttributes.PATTERN_SOLID);
> >            la.setLineAntialiasingEnable(true);
> >            a.setLineAttributes(la);
> >
> >            pa.setCullFace(PolygonAttributes.CULL_NONE);
> >            pa.setPolygonMode(PolygonAttributes.POLYGON_FILL);
> >            pa.setPolygonOffset(1.0f);
> >            //pa.setBackFaceNormalFlip(true);
> >            a.setPolygonAttributes(pa);
> >
> >            //ca.setColor(0.0f, 1.0f, 1.0f);
> >            ca.setShadeModel(ColoringAttributes.FASTEST);
> >            a.setColoringAttributes(ca);
> >
> >            ta.setTransparency(0.0f);
> >            ta.setTransparencyMode(TransparencyAttributes.FASTEST);
> >            a.setTransparencyAttributes(ta);
> >
> >            mat.setDiffuseColor(1.0f, 0.0f, 0.0f);
> >            mat.setEmissiveColor(0.5f, 0.0f, 0.0f);
> >            mat.setAmbientColor(0.0f, 1.0f, 0.0f);
> >            mat.setSpecularColor(0.0f, 0.0f, 1.0f);
> >            mat.setShininess(0.8f);
> >            //mat.setLightingEnable(true);
> >            a.setMaterial(mat);
> >        }
> >
> >        this.setAppearance(a);
> >
> >        this.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
> >        this.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
> >        this.getAppearance().setCapability(Appearance.ALLOW_MATERIAL_WRITE);
> >        this.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
> >        this.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
> >        geometry.setCapability(QuadArray.ALLOW_COORDINATE_READ);
> >        geometry.setCapability(QuadArray.ALLOW_COORDINATE_WRITE);
> >    }
> >
> >    /**
> >     * scales the vertices to the set scale
> >     * @return float[] the scaled vertices
> >     */
> >    private float[] scaleVertices(float[] verts){
> >        float scaledVerts[] = new float[verts.length];
> >        for (int i = 0; i < verts.length; i++)
> >            scaledVerts[i] = verts[i] * (float)scale;
> >        return scaledVerts;
> >    }
> >
> >    /**
> >     * changes the Vertices to the type of shape changes
> >     [EMAIL PROTECTED] aType the type to change to
> >     */
> >    public void changeType(int aType) {
> >        type = aType;
> >        Point3f[][] tempVerts;
> >
> >        switch (type) {
> >        case CUBE:
> >        tempVerts = CUBE_VERTS;
> >        break;
> >        case PIZZA:
> >        tempVerts = PIZZA_VERTS;
> >        break;
> >        default:
> >        tempVerts = CUBE_VERTS;
> >        LOG.log(Level.SEVERE, "Invalid type");
> >        break;
> >        }
> >
> >        for (int i = FRONT; i <= BOTTOM; i++) {
> >            for (int j = 0; j < tempVerts[i].length; j++) {
> >                geometry.setCoordinate(i * 4 + j, tempVerts[i][j]);
> >                geometry.setNormal(i * 4 + j, normals[i]);
> >            }
> >        }
> >    }
> >
> >    /**
> >     * generates the normals for the geometry
> >     */
> >    private void generateNormals() {
> >        for (int i = 0; i < geometry.getValidVertexCount(); i++) {
> >            //geometry.setCoordinates(i * 4, tempVerts[i]);
> >            Vector3f x = new Vector3f(normals[i/4]);
> >            //x.negate();
> >            geometry.setNormal(i, x);
> >        }
> >    }
> >
> >    /**
> >     * Returns the scale of the Item
> >     * @return double scale
> >     */
> >    public double getScale() {
> >        return scale;
> >    }
> >    /**
> >     * Returns the type of the Item
> >     * @return int type
> >     */
> >    public int getType() {
> >        return type;
> >    }
> >
> >}
> >
> >
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to